From 527ffc5e1b1e7a2c2d76d862fb575539c66caae5 Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 22 Jun 2014 21:41:50 +0100 Subject: [PATCH] Finishing error handling Former-commit-id: c9850ccb110029d9f8b4d774afdabe620ec5bd6b --- src/ImageProcessor/Processors/AutoRotate.cs | 9 ++++++++- src/ImageProcessor/Processors/BackgroundColor.cs | 9 ++++++++- src/ImageProcessor/Processors/Format.cs | 15 +++++++++++++-- src/ImageProcessor/Processors/Quality.cs | 15 ++++++++++++++- src/ImageProcessor/Processors/Watermark.cs | 2 +- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/ImageProcessor/Processors/AutoRotate.cs b/src/ImageProcessor/Processors/AutoRotate.cs index 251ba308b..521d0c2e9 100644 --- a/src/ImageProcessor/Processors/AutoRotate.cs +++ b/src/ImageProcessor/Processors/AutoRotate.cs @@ -11,8 +11,11 @@ namespace ImageProcessor.Processors { + using System; using System.Collections.Generic; using System.Drawing; + + using ImageProcessor.Core.Common.Exceptions; using ImageProcessor.Imaging; /// @@ -93,7 +96,11 @@ namespace ImageProcessor.Processors image = newImage; } } - catch + catch (Exception ex) + { + throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); + } + finally { if (newImage != null) { diff --git a/src/ImageProcessor/Processors/BackgroundColor.cs b/src/ImageProcessor/Processors/BackgroundColor.cs index b6d97eb19..8ba8bf2a2 100644 --- a/src/ImageProcessor/Processors/BackgroundColor.cs +++ b/src/ImageProcessor/Processors/BackgroundColor.cs @@ -10,9 +10,12 @@ namespace ImageProcessor.Processors { + using System; using System.Collections.Generic; using System.Drawing; + using ImageProcessor.Core.Common.Exceptions; + /// /// Changes the background color of an image. /// @@ -68,7 +71,11 @@ namespace ImageProcessor.Processors image.Dispose(); image = newImage; } - catch + catch (Exception ex) + { + throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); + } + finally { if (newImage != null) { diff --git a/src/ImageProcessor/Processors/Format.cs b/src/ImageProcessor/Processors/Format.cs index 921b5c939..2f67ad71a 100644 --- a/src/ImageProcessor/Processors/Format.cs +++ b/src/ImageProcessor/Processors/Format.cs @@ -10,8 +10,11 @@ namespace ImageProcessor.Processors { + using System; using System.Collections.Generic; using System.Drawing; + + using ImageProcessor.Core.Common.Exceptions; using ImageProcessor.Imaging.Formats; /// @@ -57,8 +60,16 @@ namespace ImageProcessor.Processors /// public Image ProcessImage(ImageFactory factory) { - ISupportedImageFormat format = this.DynamicParameter; - factory.Format(format); + try + { + ISupportedImageFormat format = this.DynamicParameter; + factory.Format(format); + } + catch (Exception ex) + { + throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); + } + return factory.Image; } } diff --git a/src/ImageProcessor/Processors/Quality.cs b/src/ImageProcessor/Processors/Quality.cs index bb89a3e6b..28bb445fb 100644 --- a/src/ImageProcessor/Processors/Quality.cs +++ b/src/ImageProcessor/Processors/Quality.cs @@ -11,8 +11,13 @@ namespace ImageProcessor.Processors { #region Using + + using System; using System.Collections.Generic; using System.Drawing; + + using ImageProcessor.Core.Common.Exceptions; + #endregion /// @@ -58,7 +63,15 @@ namespace ImageProcessor.Processors /// public Image ProcessImage(ImageFactory factory) { - factory.CurrentImageFormat.Quality = this.DynamicParameter; + try + { + factory.CurrentImageFormat.Quality = this.DynamicParameter; + } + catch (Exception ex) + { + throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); + } + return factory.Image; } } diff --git a/src/ImageProcessor/Processors/Watermark.cs b/src/ImageProcessor/Processors/Watermark.cs index b0ff1e00d..d6e9a97fe 100644 --- a/src/ImageProcessor/Processors/Watermark.cs +++ b/src/ImageProcessor/Processors/Watermark.cs @@ -180,4 +180,4 @@ namespace ImageProcessor.Processors } } } -} +} \ No newline at end of file