Browse Source

Change ImageFormatException to InvalidImageContentException

pull/1190/head
Brian Popow 6 years ago
parent
commit
08b5c4cb83
  1. 14
      src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
  2. 4
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  3. 4
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  4. 4
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  5. 4
      src/ImageSharp/Formats/Png/PngDecoder.cs
  6. 4
      src/ImageSharp/Formats/Tga/TgaDecoder.cs

14
src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors.ImageSharp
{
/// <summary>
@ -18,5 +20,17 @@ namespace SixLabors.ImageSharp
: base(errorMessage)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="InvalidImageContentException"/> class with the name of the
/// parameter that causes this exception.
/// </summary>
/// <param name="errorMessage">The error message that explains the reason for this exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic)
/// if no inner exception is specified.</param>
public InvalidImageContentException(string errorMessage, Exception innerException)
: base(errorMessage, innerException)
{
}
}
}

4
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -43,9 +43,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex);
}
}

4
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -38,9 +38,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
}
}

4
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -32,9 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
(int w, int h) = (decoder.ImageWidth, decoder.ImageHeight);
// TODO: use InvalidImageContentException here, if we decide to define it
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
}
}

4
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -54,9 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Png
{
Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
}
}

4
src/ImageSharp/Formats/Tga/TgaDecoder.cs

@ -28,9 +28,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
Size dims = decoder.Dimensions;
// TODO: use InvalidImageContentException here, if we decide to define it
// https://github.com/SixLabors/ImageSharp/issues/1110
throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
}
}

Loading…
Cancel
Save