cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 2 | Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3 | dedicated to making software imaging solutions freely available. |
| 4 | |
| 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
| 7 | |
| 8 | http://www.imagemagick.org/script/license.php |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | MagickCore exception private methods. |
| 17 | */ |
| 18 | #ifndef _MAGICKCORE_EXCEPTION_PRIVATE_H |
| 19 | #define _MAGICKCORE_EXCEPTION_PRIVATE_H |
| 20 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 21 | #include "MagickCore/log.h" |
cristy | 8ed6011 | 2012-12-13 14:56:15 +0000 | [diff] [blame] | 22 | #include "MagickCore/magick.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 23 | #include "MagickCore/string_.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 24 | |
cristy | 6398ec7 | 2013-11-28 02:00:27 +0000 | [diff] [blame] | 25 | #if defined(__cplusplus) || defined(c_plusplus) |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 29 | #define ThrowBinaryException(severity,tag,context) \ |
| 30 | { \ |
| 31 | if (image != (Image *) NULL) \ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 32 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 33 | tag == (const char *) NULL ? "unknown" : tag,"`%s'",context); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 34 | return(MagickFalse); \ |
| 35 | } |
| 36 | #define ThrowFatalException(severity,tag) \ |
| 37 | { \ |
cristy | 5bf97b5 | 2011-01-24 13:21:15 +0000 | [diff] [blame] | 38 | char \ |
| 39 | *message; \ |
| 40 | \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 41 | ExceptionInfo \ |
dirk | e31feb8 | 2014-06-20 11:03:07 +0000 | [diff] [blame] | 42 | *exception; \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 43 | \ |
dirk | e31feb8 | 2014-06-20 11:03:07 +0000 | [diff] [blame] | 44 | exception=AcquireExceptionInfo(); \ |
cristy | 5bf97b5 | 2011-01-24 13:21:15 +0000 | [diff] [blame] | 45 | message=GetExceptionMessage(errno); \ |
dirk | e31feb8 | 2014-06-20 11:03:07 +0000 | [diff] [blame] | 46 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 47 | tag == (const char *) NULL ? "unknown" : tag,"`%s'",message); \ |
cristy | 5bf97b5 | 2011-01-24 13:21:15 +0000 | [diff] [blame] | 48 | message=DestroyString(message); \ |
dirk | e31feb8 | 2014-06-20 11:03:07 +0000 | [diff] [blame] | 49 | CatchException(exception); \ |
| 50 | (void) DestroyExceptionInfo(exception); \ |
cristy | 8ed6011 | 2012-12-13 14:56:15 +0000 | [diff] [blame] | 51 | MagickCoreTerminus(); \ |
cristy | b4d552c | 2012-12-13 15:42:17 +0000 | [diff] [blame] | 52 | _exit((int) (severity-FatalErrorException)+1); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 53 | } |
| 54 | #define ThrowFileException(exception,severity,tag,context) \ |
| 55 | { \ |
cristy | 5bf97b5 | 2011-01-24 13:21:15 +0000 | [diff] [blame] | 56 | char \ |
| 57 | *message; \ |
| 58 | \ |
| 59 | message=GetExceptionMessage(errno); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 60 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 61 | tag == (const char *) NULL ? "unknown" : tag,"'%s': %s",context,message); \ |
cristy | 5bf97b5 | 2011-01-24 13:21:15 +0000 | [diff] [blame] | 62 | message=DestroyString(message); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 63 | } |
| 64 | #define ThrowImageException(severity,tag) \ |
| 65 | { \ |
| 66 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 67 | tag == (const char *) NULL ? "unknown" : tag,"`%s'",image->filename); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | return((Image *) NULL); \ |
| 69 | } |
| 70 | #define ThrowReaderException(severity,tag) \ |
| 71 | { \ |
| 72 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 73 | tag == (const char *) NULL ? "unknown" : tag,"`%s'",image_info->filename); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 74 | if ((image) != (Image *) NULL) \ |
| 75 | { \ |
| 76 | (void) CloseBlob(image); \ |
| 77 | image=DestroyImageList(image); \ |
| 78 | } \ |
| 79 | return((Image *) NULL); \ |
| 80 | } |
| 81 | #define ThrowWriterException(severity,tag) \ |
| 82 | { \ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 83 | (void) ThrowMagickException(exception,GetMagickModule(),severity, \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 84 | tag == (const char *) NULL ? "unknown" : tag,"`%s'",image->filename); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | if (image_info->adjoin != MagickFalse) \ |
| 86 | while (image->previous != (Image *) NULL) \ |
| 87 | image=image->previous; \ |
| 88 | (void) CloseBlob(image); \ |
| 89 | return(MagickFalse); \ |
| 90 | } |
| 91 | |
dirk | e31feb8 | 2014-06-20 11:03:07 +0000 | [diff] [blame] | 92 | extern MagickPrivate void |
| 93 | InitializeExceptionInfo(ExceptionInfo *); |
| 94 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 95 | #if defined(__cplusplus) || defined(c_plusplus) |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #endif |