WizardsToolkit  1.0.7
exception-private.h
Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.
00006   obtain a copy of the License at
00007 
00008     http://www.wizards-toolkit.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   Wizard's Toolkit private exception methods.
00017 */
00018 #ifndef _WIZARDSTOOLKIT_EXCEPTION_PRIVATE_H
00019 #define _WIZARDSTOOLKIT_EXCEPTION_PRIVATE_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include "wizard/log.h"
00026 #include "wizard/string_.h"
00027 
00028 #define CatchWizardException(severity,tag,context) \
00029 { \
00030   ExceptionInfo \
00031     *exception; \
00032  \
00033   exception=AcquireExceptionInfo(); \
00034   (void) ThrowWizardException(exception,GetWizardModule(),severity,tag,context); \
00035   CatchException(exception); \
00036   exception=DestroyExceptionInfo(exception); \
00037 }
00038 
00039 #if defined(WIZARDSTOOLKIT_Debug)
00040 #define WizardAssert(domain,predicate) \
00041 { \
00042   assert(predicate); \
00043 }
00044 #else 
00045 #define WizardAssert(domain,predicate) \
00046 { \
00047   if ((WizardBooleanType) (predicate) == WizardFalse) \
00048     ThrowWizardFatalError(domain,AssertError); \
00049 }
00050 #endif 
00051 
00052 #define ThrowFileException(exception,severity,context) \
00053 { \
00054   char \
00055      *message; \
00056  \
00057   message=GetExceptionMessage(errno); \
00058   (void) ThrowWizardException(exception,GetWizardModule(),severity, \
00059     "file exception `%s': %s",context,message); \
00060   message=DestroyString(message); \
00061 }
00062 
00063 #define ThrowWizardFatalError(domain,error) \
00064 { \
00065   char \
00066     context[MaxTextExtent], \
00067     tag[MaxTextExtent]; \
00068  \
00069   (void) FormatLocaleString(tag,MaxTextExtent,"%ld\n",(long) domain); \
00070   (void) FormatLocaleString(context,MaxTextExtent,"%ld\n",(long) error); \
00071   CatchWizardException(UndefinedException,tag,context); \
00072   _exit((domain << 3) | error); \
00073 }
00074 
00075 #define ThrowFatalException(severity,tag) \
00076 { \
00077   char \
00078      *message; \
00079  \
00080   message=GetExceptionMessage(errno); \
00081   CatchWizardException(severity,tag,message); \
00082   message=DestroyString(message); \
00083   _exit(127); \
00084 }
00085 
00086 #if defined(__cplusplus) || defined(c_plusplus)
00087 }
00088 #endif
00089 
00090 #endif