Class CorruptDataException
- Namespace
- Egami
- Assembly
- Egami.dll
Thrown when data matches a format but breaks its rules, such as a bad checksum, a truncated stream or an invalid table.
public sealed class CorruptDataException : EgamiException, ISerializable
- Inheritance
-
CorruptDataException
- Implements
- Inherited Members
Examples
EgamiContext strict = EgamiContext.Default with
{
Limits = SafetyLimits.Default with { MaxPixels = 25_000_000, MaxTotalBytes = 256L * 1024 * 1024 },
};
try
{
// Read the header first: cheap, and it rejects what you do not want before any pixel memory is used.
RasterInfo info = Raster.Probe(upload, strict);
if (info.Width > 8000 || info.Height > 8000)
{
throw new InvalidDataException("Too large.");
}
using Raster image = Raster.Load(upload, strict, new ReaderOptions { Recovery = RecoveryMode.Strict });
Console.WriteLine($"{info.Format.Name} {image.Width} × {image.Height}");
}
catch (UnsupportedFormatException)
{
Console.WriteLine("Not an image format we accept.");
}
catch (LimitExceededException e)
{
Console.WriteLine($"Over the {e.LimitName} limit.");
}
catch (CorruptDataException e)
{
Console.WriteLine($"Damaged at byte {e.Offset}.");
}
Constructors
CorruptDataException(string, long, string, Exception?)
Initializes a new instance of the CorruptDataException class.
public CorruptDataException(string formatName, long offset, string problem, Exception? innerException = null)
Parameters
formatNamestringThe format being read, such as "PNG".
offsetlongThe byte offset of the problem in the input, or -1 if unknown.
problemstringWhat is wrong, as a sentence.
innerExceptionExceptionThe exception that caused this one, if any.
Properties
FormatName
Gets the name of the format being read.
public string FormatName { get; }
Property Value
Offset
Gets the byte offset of the problem in the input, or -1 if unknown.
public long Offset { get; }