|
WizardsToolkit
1.0.7
|
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % EEEEE X X CCCC EEEEE PPPP TTTTT IIIII OOO N N % 00007 % E X X C E P P T I O O NN N % 00008 % EEE X C EEE PPPP T I O O N N N % 00009 % E X X C E P T I O O N NN % 00010 % EEEEE X X CCCC EEEEE P T IIIII OOO N N % 00011 % % 00012 % % 00013 % Wizards Toolkit Exception Methods % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % July 1993 % 00018 % % 00019 % % 00020 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % 00021 % dedicated to making software imaging solutions freely available. % 00022 % % 00023 % You may not use this file except in compliance with the License. You may % 00024 % obtain a copy of the License at % 00025 % % 00026 % http://www.wizards-toolkit.org/script/license.php % 00027 % % 00028 % Unless required by applicable law or agreed to in writing, software % 00029 % distributed under the License is distributed on an "AS IS" BASIS, % 00030 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00031 % See the License for the specific language governing permissions and % 00032 % limitations under the License. % 00033 % % 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 % 00036 % 00037 % 00038 */ 00039 00040 /* 00041 Include declarations. 00042 */ 00043 #include "wizard/studio.h" 00044 #include "wizard/client.h" 00045 #include "wizard/exception.h" 00046 #include "wizard/exception-private.h" 00047 #include "wizard/hashmap.h" 00048 #include "wizard/log.h" 00049 #include "wizard/memory_.h" 00050 #include "wizard/string_.h" 00051 #include "wizard/utility.h" 00052 #include "wizard/wizard.h" 00053 00054 /* 00055 Typedef declarations. 00056 */ 00057 struct _ExceptionInfo 00058 { 00059 ExceptionType 00060 severity; 00061 00062 char 00063 *reason, 00064 *description; 00065 00066 void 00067 *exceptions; 00068 00069 WizardBooleanType 00070 relinquish; 00071 00072 SemaphoreInfo 00073 *semaphore; 00074 00075 size_t 00076 signature; 00077 }; 00078 00079 /* 00080 Forward declarations. 00081 */ 00082 #if defined(__cplusplus) || defined(c_plusplus) 00083 extern "C" { 00084 #endif 00085 00086 static void 00087 DefaultErrorHandler(const ExceptionType,const char *,const char *), 00088 DefaultFatalErrorHandler(const ExceptionType,const char *,const char *), 00089 DefaultWarningHandler(const ExceptionType,const char *,const char *); 00090 00091 #if defined(__cplusplus) || defined(c_plusplus) 00092 } 00093 #endif 00094 00095 /* 00096 Global declarations. 00097 */ 00098 static ErrorHandler 00099 error_handler = DefaultErrorHandler; 00100 00101 static FatalErrorHandler 00102 fatal_error_handler = DefaultFatalErrorHandler; 00103 00104 static WarningHandler 00105 warning_handler = DefaultWarningHandler; 00106 00107 /* 00108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00109 % % 00110 % % 00111 % % 00112 % A c q u i r e E x c e p t i o n I n f o % 00113 % % 00114 % % 00115 % % 00116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00117 % 00118 % AcquireExceptionInfo() allocates the ExceptionInfo structure. 00119 % 00120 % The format of the AcquireExceptionInfo method is: 00121 % 00122 % ExceptionInfo *AcquireExceptionInfo(void) 00123 % 00124 */ 00125 WizardExport ExceptionInfo *AcquireExceptionInfo(void) 00126 { 00127 ExceptionInfo 00128 *exception; 00129 00130 exception=(ExceptionInfo *) AcquireWizardMemory(sizeof(*exception)); 00131 if (exception == (ExceptionInfo *) NULL) 00132 ThrowFatalException(ResourceFatalError,"memory allocation failed `%s'"); 00133 (void) ResetWizardMemory(exception,0,sizeof(*exception)); 00134 GetExceptionInfo(exception); 00135 exception->relinquish=WizardTrue; 00136 exception->signature=WizardSignature; 00137 return(exception); 00138 } 00139 00140 /* 00141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00142 % % 00143 % % 00144 % % 00145 % C l e a r W i z a r d E x c e p t i o n % 00146 % % 00147 % % 00148 % % 00149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00150 % 00151 % ClearWizardException() clears any exception that may not have been caught 00152 % yet. 00153 % 00154 % The format of the ClearWizardException method is: 00155 % 00156 % ClearWizardException(ExceptionInfo *exception) 00157 % 00158 % A description of each parameter follows: 00159 % 00160 % o exception: The exception info. 00161 % 00162 */ 00163 00164 static void *DestroyExceptionElement(void *exception) 00165 { 00166 register ExceptionInfo 00167 *p; 00168 00169 p=(ExceptionInfo *) exception; 00170 if (p->reason != (char *) NULL) 00171 p->reason=(char *) RelinquishWizardMemory(p->reason); 00172 if (p->description != (char *) NULL) 00173 p->description=(char *) RelinquishWizardMemory(p->description); 00174 p=(ExceptionInfo *) RelinquishWizardMemory(p); 00175 return((void *) NULL); 00176 } 00177 00178 WizardExport void ClearWizardException(ExceptionInfo *exception) 00179 { 00180 register ExceptionInfo 00181 *p; 00182 00183 assert(exception != (ExceptionInfo *) NULL); 00184 assert(exception->signature == WizardSignature); 00185 if (exception->exceptions == (void *) NULL) 00186 return; 00187 LockSemaphoreInfo(exception->semaphore); 00188 p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) 00189 exception->exceptions); 00190 while (p != (ExceptionInfo *) NULL) 00191 { 00192 p=(ExceptionInfo *) DestroyExceptionElement(p); 00193 p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) 00194 exception->exceptions); 00195 } 00196 exception->severity=UndefinedException; 00197 exception->reason=(char *) NULL; 00198 exception->description=(char *) NULL; 00199 UnlockSemaphoreInfo(exception->semaphore); 00200 errno=0; 00201 } 00202 00203 /* 00204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00205 % % 00206 % % 00207 % % 00208 % C a t c h E x c e p t i o n % 00209 % % 00210 % % 00211 % % 00212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00213 % 00214 % CatchException() returns if no exceptions is found otherwise it reports 00215 % the exception as a warning, error, or fatal depending on the severity. 00216 % 00217 % The format of the CatchException method is: 00218 % 00219 % CatchException(ExceptionInfo *exception) 00220 % 00221 % A description of each parameter follows: 00222 % 00223 % o exception: The exception info. 00224 % 00225 */ 00226 WizardExport void CatchException(ExceptionInfo *exception) 00227 { 00228 register const ExceptionInfo 00229 *p; 00230 00231 assert(exception != (ExceptionInfo *) NULL); 00232 assert(exception->signature == WizardSignature); 00233 if (exception->exceptions == (void *) NULL) 00234 return; 00235 LockSemaphoreInfo(exception->semaphore); 00236 ResetLinkedListIterator((LinkedListInfo *) exception->exceptions); 00237 p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) 00238 exception->exceptions); 00239 while (p != (const ExceptionInfo *) NULL) 00240 { 00241 if ((p->severity >= WarningException) && (p->severity < ErrorException)) 00242 WizardWarning(p->severity,p->reason,p->description); 00243 if ((p->severity >= ErrorException) && (p->severity < FatalErrorException)) 00244 WizardError(p->severity,p->reason,p->description); 00245 if (exception->severity >= FatalErrorException) 00246 WizardFatalError(p->severity,p->reason,p->description); 00247 p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) 00248 exception->exceptions); 00249 } 00250 UnlockSemaphoreInfo(exception->semaphore); 00251 ClearWizardException(exception); 00252 } 00253 00254 /* 00255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00256 % % 00257 % % 00258 % % 00259 + D e f a u l t E r r o r H a n d l e r % 00260 % % 00261 % % 00262 % % 00263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00264 % 00265 % DefaultErrorHandler() displays an error reason. 00266 % 00267 % The format of the DefaultErrorHandler method is: 00268 % 00269 % void WizardError(const ExceptionType severity,const char *reason, 00270 % const char *description) 00271 % 00272 % A description of each parameter follows: 00273 % 00274 % o severity: Specifies the numeric error category. 00275 % 00276 % o reason: Specifies the reason to display before terminating the 00277 % program. 00278 % 00279 % o description: Specifies any description to the reason. 00280 % 00281 */ 00282 static void DefaultErrorHandler(const ExceptionType wizard_unused(severity), 00283 const char *reason,const char *description) 00284 { 00285 if (reason == (char *) NULL) 00286 return; 00287 (void) fprintf(stderr,"%s: %s",GetClientName(),reason); 00288 if (description != (char *) NULL) 00289 (void) fprintf(stderr," (%s)",description); 00290 (void) fprintf(stderr,".\n"); 00291 (void) fflush(stderr); 00292 } 00293 00294 /* 00295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00296 % % 00297 % % 00298 % % 00299 + D e f a u l t F a t a l E r r o r H a n d l e r % 00300 % % 00301 % % 00302 % % 00303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00304 % 00305 % DefaultFatalErrorHandler() displays an error reason and then terminates the 00306 % program. 00307 % 00308 % The format of the DefaultFatalErrorHandler method is: 00309 % 00310 % void WizardFatalError(const ExceptionType severity,const char *reason, 00311 % const char *description) 00312 % 00313 % A description of each parameter follows: 00314 % 00315 % o severity: Specifies the numeric error category. 00316 % 00317 % o reason: Specifies the reason to display before terminating the 00318 % program. 00319 % 00320 % o description: Specifies any description to the reason. 00321 % 00322 */ 00323 static void DefaultFatalErrorHandler(const ExceptionType severity, 00324 const char *reason,const char *description) 00325 { 00326 if (reason == (char *) NULL) 00327 return; 00328 (void) fprintf(stderr,"%s: %s",GetClientName(),reason); 00329 if (description != (char *) NULL) 00330 (void) fprintf(stderr," (%s)",description); 00331 (void) fprintf(stderr,".\n"); 00332 (void) fflush(stderr); 00333 WizardsToolkitTerminus(); 00334 exit(1); 00335 } 00336 00337 /* 00338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00339 % % 00340 % % 00341 % % 00342 + D e f a u l t W a r n i n g H a n d l e r % 00343 % % 00344 % % 00345 % % 00346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00347 % 00348 % DefaultWarningHandler() displays a warning reason. 00349 % 00350 % The format of the DefaultWarningHandler method is: 00351 % 00352 % void DefaultWarningHandler(const ExceptionType warning, 00353 % const char *reason,const char *description) 00354 % 00355 % A description of each parameter follows: 00356 % 00357 % o warning: Specifies the numeric warning category. 00358 % 00359 % o reason: Specifies the reason to display before terminating the 00360 % program. 00361 % 00362 % o description: Specifies any description to the reason. 00363 % 00364 */ 00365 static void DefaultWarningHandler(const ExceptionType wizard_unused(severity), 00366 const char *reason,const char *description) 00367 { 00368 if (reason == (char *) NULL) 00369 return; 00370 (void) fprintf(stderr,"%s: %s",GetClientName(),reason); 00371 if (description != (char *) NULL) 00372 (void) fprintf(stderr," (%s)",description); 00373 (void) fprintf(stderr,".\n"); 00374 (void) fflush(stderr); 00375 } 00376 00377 /* 00378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00379 % % 00380 % % 00381 % % 00382 % D e s t r o y E x c e p t i o n I n f o % 00383 % % 00384 % % 00385 % % 00386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00387 % 00388 % DestroyExceptionInfo() deallocates memory associated with an exception. 00389 % 00390 % The format of the DestroyExceptionInfo method is: 00391 % 00392 % ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) 00393 % 00394 % A description of each parameter follows: 00395 % 00396 % o exception: The exception info. 00397 % 00398 */ 00399 WizardExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) 00400 { 00401 assert(exception != (ExceptionInfo *) NULL); 00402 assert(exception->signature == WizardSignature); 00403 LockSemaphoreInfo(exception->semaphore); 00404 exception->severity=UndefinedException; 00405 if (exception->exceptions != (void *) NULL) 00406 exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) 00407 exception->exceptions,DestroyExceptionElement); 00408 exception->signature=(~WizardSignature); 00409 UnlockSemaphoreInfo(exception->semaphore); 00410 DestroySemaphoreInfo(&exception->semaphore); 00411 if (exception->relinquish != WizardFalse) 00412 exception=(ExceptionInfo *) RelinquishWizardMemory(exception); 00413 return(exception); 00414 } 00415 00416 /* 00417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00418 % % 00419 % % 00420 % % 00421 % G e t E x c e p t i o n I n f o % 00422 % % 00423 % % 00424 % % 00425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00426 % 00427 % GetExceptionInfo() initializes an exception to default values. 00428 % 00429 % The format of the GetExceptionInfo method is: 00430 % 00431 % GetExceptionInfo(ExceptionInfo *exception) 00432 % 00433 % A description of each parameter follows: 00434 % 00435 % o exception: The exception info. 00436 % 00437 */ 00438 WizardExport void GetExceptionInfo(ExceptionInfo *exception) 00439 { 00440 assert(exception != (ExceptionInfo *) NULL); 00441 (void) ResetWizardMemory(exception,0,sizeof(*exception)); 00442 exception->severity=UndefinedException; 00443 exception->exceptions=(void *) NewLinkedList(0); 00444 exception->semaphore=AllocateSemaphoreInfo(); 00445 exception->signature=WizardSignature; 00446 } 00447 00448 /* 00449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00450 % % 00451 % % 00452 % % 00453 % G e t E x c e p t i o n M e s s a g e % 00454 % % 00455 % % 00456 % % 00457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00458 % 00459 % GetExceptionMessage() returns the error message defined by the specified 00460 % error code. 00461 % 00462 % The format of the GetExceptionMessage method is: 00463 % 00464 % char *GetExceptionMessage(const int error) 00465 % 00466 % A description of each parameter follows: 00467 % 00468 % o error: the error code. 00469 % 00470 */ 00471 WizardExport char *GetExceptionMessage(const int error) 00472 { 00473 char 00474 exception[MaxTextExtent]; 00475 00476 *exception='\0'; 00477 #if defined(WIZARDSTOOLKIT_HAVE_STRERROR_R) 00478 #if !defined(WIZARDSTOOLKIT_STRERROR_R_CHAR_P) 00479 (void) strerror_r(error,exception,sizeof(exception)); 00480 #else 00481 (void) CopyWizardString(exception,strerror_r(error,exception, 00482 sizeof(exception)),sizeof(exception)); 00483 #endif 00484 #else 00485 (void) CopyWizardString(exception,strerror(error),sizeof(exception)); 00486 #endif 00487 return(ConstantString(exception)); 00488 } 00489 00490 /* 00491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00492 % % 00493 % % 00494 % % 00495 % G e t L o c a l e E x c e p t i o n M e s s a g e % 00496 % % 00497 % % 00498 % % 00499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00500 % 00501 % GetLocaleExceptionMessage() converts a enumerated exception severity and tag 00502 % to a message in the current locale. 00503 % 00504 % The format of the GetLocaleExceptionMessage method is: 00505 % 00506 % const char *GetLocaleExceptionMessage(const ExceptionType severity, 00507 % const char *tag) 00508 % 00509 % A description of each parameter follows: 00510 % 00511 % o severity: the severity of the exception. 00512 % 00513 % o tag: the message tag. 00514 % 00515 */ 00516 00517 static const char *ExceptionSeverityToTag(const ExceptionType severity) 00518 { 00519 switch (severity) 00520 { 00521 case OptionWarning: return("Option/Warning/"); 00522 case RandomWarning: return("Random/Warning/"); 00523 case HashWarning: return("Hash/Warning/"); 00524 case MACWarning: return("MAC/Warning/"); 00525 case EntropyWarning: return("Entropy/Warning/"); 00526 case ConfigureWarning: return("Configure/Warning/"); 00527 case CipherWarning: return("Cipher/Warning/"); 00528 case KeymapWarning: return("Keymap/Warning/"); 00529 case AuthenticateWarning: return("Authenticate/Warning/"); 00530 case KeyringWarning: return("Keyring/Warning/"); 00531 case ParseWarning: return("Parse/Warning/"); 00532 case UserWarning: return("User/Warning/"); 00533 case SplayTreeWarning: return("SplayTree/Warning/"); 00534 case HashmapWarning: return("Hashmap/Warning/"); 00535 case LogWarning: return("Log/Warning/"); 00536 case StringWarning: return("String/Warning/"); 00537 case FileWarning: return("File/Warning/"); 00538 case BlobWarning: return("Blob/Warning/"); 00539 case ResourceWarning: return("ResourceLimit/Warning/"); 00540 case OptionError: return("Option/Error/"); 00541 case RandomError: return("Random/Error/"); 00542 case HashError: return("Hash/Error/"); 00543 case MACError: return("MAC/Error/"); 00544 case EntropyError: return("Entropy/Error/"); 00545 case ConfigureError: return("Configure/Error/"); 00546 case CipherError: return("Cipher/Error/"); 00547 case KeymapError: return("Keymap/Error/"); 00548 case AuthenticateError: return("Authenticate/Error/"); 00549 case KeyringError: return("Keyring/Error/"); 00550 case ParseError: return("Parse/Error/"); 00551 case UserError: return("User/Error/"); 00552 case SplayTreeError: return("SplayTree/Error/"); 00553 case StringError: return("String/Error/"); 00554 case FileError: return("File/Error/"); 00555 case BlobError: return("Blob/Error/"); 00556 case ResourceError: return("ResourceLimit/Error/"); 00557 case OptionFatalError: return("Option/FatalError/"); 00558 case RandomFatalError: return("Random/FatalError/"); 00559 case HashFatalError: return("Hash/FatalError/"); 00560 case MACFatalError: return("MAC/FatalError/"); 00561 case EntropyFatalError: return("Entropy/FatalError/"); 00562 case ConfigureFatalError: return("Configure/FatalError/"); 00563 case CipherFatalError: return("Cipher/FatalError/"); 00564 case KeymapFatalError: return("Keymap/FatalError/"); 00565 case AuthenticateFatalError: return("Authenticate/FatalError/"); 00566 case KeyringFatalError: return("Keyring/FatalError/"); 00567 case ParseFatalError: return("Parse/FatalError/"); 00568 case UserFatalError: return("User/FatalError/"); 00569 case SplayTreeFatalError: return("SplayTree/FatalError/"); 00570 case HashmapFatalError: return("Hashmap/FatalError/"); 00571 case LogFatalError: return("Log/FatalError/"); 00572 case StringFatalError: return("String/FatalError/"); 00573 case FileFatalError: return("File/FatalError/"); 00574 case BlobFatalError: return("Blob/FatalError/"); 00575 case ResourceFatalError: return("ResourceLimit/FatalError/"); 00576 default: break; 00577 } 00578 return(""); 00579 } 00580 00581 WizardExport const char *GetLocaleExceptionMessage(const ExceptionType severity, 00582 const char *tag) 00583 { 00584 #if defined(WIZARDSTOOLKIT_LOCALE) 00585 char 00586 message[MaxTextExtent]; 00587 00588 const char 00589 *locale_message; 00590 00591 assert(tag != (const char *) NULL); 00592 (void) FormatLocaleString(message,MaxTextExtent,"Exception/%s%s", 00593 ExceptionSeverityToTag(severity),tag); 00594 locale_message=GetLocaleMessage(message); 00595 if (locale_message == (const char *) NULL) 00596 return(tag); 00597 if (locale_message == message) 00598 return(tag); 00599 return(locale_message); 00600 #else 00601 return(tag); 00602 #endif 00603 } 00604 00605 /* 00606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00607 % % 00608 % % 00609 % % 00610 % G e t E x c e p t i o n S e v e r i t y % 00611 % % 00612 % % 00613 % % 00614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00615 % 00616 % GetExceptionSeverity() returns the exception severity. 00617 % 00618 % The format of the GetExceptionSeverity method is: 00619 % 00620 % ExceptionType GetExceptionSeverity(const ExceptionInfo *exception) 00621 % 00622 % A description of each parameter follows: 00623 % 00624 % o exception: The exception. 00625 % 00626 */ 00627 WizardExport ExceptionType GetExceptionSeverity(const ExceptionInfo *exception) 00628 { 00629 assert(exception != (ExceptionInfo *) NULL); 00630 assert(exception->signature == WizardSignature); 00631 return(exception->severity); 00632 } 00633 00634 /* 00635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00636 % % 00637 % % 00638 % % 00639 % I n h e r i t E x c e p t i o n % 00640 % % 00641 % % 00642 % % 00643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00644 % 00645 % InheritException() inherits an exception from a related exception. 00646 % 00647 % The format of the InheritException method is: 00648 % 00649 % InheritException(ExceptionInfo *exception,const ExceptionInfo *relative) 00650 % 00651 % A description of each parameter follows: 00652 % 00653 % o exception: The exception info. 00654 % 00655 % o relative: The related exception info. 00656 % 00657 % 00658 */ 00659 WizardExport void InheritException(ExceptionInfo *exception, 00660 const ExceptionInfo *relative) 00661 { 00662 register const ExceptionInfo 00663 *p; 00664 00665 assert(exception != (ExceptionInfo *) NULL); 00666 assert(exception->signature == WizardSignature); 00667 assert(relative != (ExceptionInfo *) NULL); 00668 assert(relative->signature == WizardSignature); 00669 if (relative->exceptions == (void *) NULL) 00670 return; 00671 LockSemaphoreInfo(exception->semaphore); 00672 ResetLinkedListIterator((LinkedListInfo *) relative->exceptions); 00673 p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) 00674 relative->exceptions); 00675 while (p != (const ExceptionInfo *) NULL) 00676 { 00677 (void) ThrowException(exception,p->severity,p->reason,p->description); 00678 p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) 00679 relative->exceptions); 00680 } 00681 UnlockSemaphoreInfo(exception->semaphore); 00682 } 00683 00684 /* 00685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00686 % % 00687 % % 00688 % % 00689 % W i z a r d E r r o r % 00690 % % 00691 % % 00692 % % 00693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00694 % 00695 % WizardError() calls the exception handler methods with an error reason. 00696 % 00697 % The format of the WizardError method is: 00698 % 00699 % void WizardError(const ExceptionType error,const char *reason, 00700 % const char *description) 00701 % 00702 % A description of each parameter follows: 00703 % 00704 % o exception: Specifies the numeric error category. 00705 % 00706 % o reason: Specifies the reason to display before terminating the 00707 % program. 00708 % 00709 % o description: Specifies any description to the reason. 00710 % 00711 % 00712 */ 00713 WizardExport void WizardError(const ExceptionType error,const char *reason, 00714 const char *description) 00715 { 00716 if (error_handler != (ErrorHandler) NULL) 00717 (*error_handler)(error,reason,description); 00718 } 00719 00720 /* 00721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00722 % % 00723 % % 00724 % % 00725 % W i z a r d F a t al E r r o r % 00726 % % 00727 % % 00728 % % 00729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00730 % 00731 % WizardFatalError() calls the fatal exception handler methods with an error 00732 % reason. 00733 % 00734 % The format of the WizardError method is: 00735 % 00736 % void WizardFatalError(const ExceptionType error,const char *reason, 00737 % const char *description) 00738 % 00739 % A description of each parameter follows: 00740 % 00741 % o exception: Specifies the numeric error category. 00742 % 00743 % o reason: Specifies the reason to display before terminating the 00744 % program. 00745 % 00746 % o description: Specifies any description to the reason. 00747 % 00748 */ 00749 WizardExport void WizardFatalError(const ExceptionType error,const char *reason, 00750 const char *description) 00751 { 00752 if (fatal_error_handler != (ErrorHandler) NULL) 00753 (*fatal_error_handler)(error,reason,description); 00754 } 00755 00756 /* 00757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00758 % % 00759 % % 00760 % % 00761 % W i z a r d W a r n i n g % 00762 % % 00763 % % 00764 % % 00765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00766 % 00767 % WizardWarning() calls the warning handler methods with a warning reason. 00768 % 00769 % The format of the WizardWarning method is: 00770 % 00771 % void WizardWarning(const ExceptionType warning,const char *reason, 00772 % const char *description) 00773 % 00774 % A description of each parameter follows: 00775 % 00776 % o warning: The warning severity. 00777 % 00778 % o reason: Define the reason for the warning. 00779 % 00780 % o description: Describe the warning. 00781 % 00782 */ 00783 WizardExport void WizardWarning(const ExceptionType warning,const char *reason, 00784 const char *description) 00785 { 00786 if (warning_handler != (WarningHandler) NULL) 00787 (*warning_handler)(warning,reason,description); 00788 } 00789 00790 /* 00791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00792 % % 00793 % % 00794 % % 00795 % S e t E r r o r H a n d l e r % 00796 % % 00797 % % 00798 % % 00799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00800 % 00801 % SetErrorHandler() sets the exception handler to the specified method 00802 % and returns the previous exception handler. 00803 % 00804 % The format of the SetErrorHandler method is: 00805 % 00806 % ErrorHandler SetErrorHandler(ErrorHandler handler) 00807 % 00808 % A description of each parameter follows: 00809 % 00810 % o handler: The method to handle errors. 00811 % 00812 */ 00813 WizardExport ErrorHandler SetErrorHandler(ErrorHandler handler) 00814 { 00815 ErrorHandler 00816 previous_handler; 00817 00818 previous_handler=error_handler; 00819 error_handler=handler; 00820 return(previous_handler); 00821 } 00822 00823 /* 00824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00825 % % 00826 % % 00827 % % 00828 % S e t F a t a l E r r o r H a n d l e r % 00829 % % 00830 % % 00831 % % 00832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00833 % 00834 % SetFatalErrorHandler() sets the fatal exception handler to the specified 00835 % method and returns the previous fatal exception handler. 00836 % 00837 % The format of the SetErrorHandler method is: 00838 % 00839 % ErrorHandler SetErrorHandler(ErrorHandler handler) 00840 % 00841 % A description of each parameter follows: 00842 % 00843 % o handler: The method to handle errors. 00844 % 00845 */ 00846 WizardExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler) 00847 { 00848 FatalErrorHandler 00849 previous_handler; 00850 00851 previous_handler=fatal_error_handler; 00852 fatal_error_handler=handler; 00853 return(previous_handler); 00854 } 00855 00856 /* 00857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00858 % % 00859 % % 00860 % % 00861 % S e t W a r n i n g H a n d l e r % 00862 % % 00863 % % 00864 % % 00865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00866 % 00867 % SetWarningHandler() sets the warning handler to the specified method 00868 % and returns the previous warning handler. 00869 % 00870 % The format of the SetWarningHandler method is: 00871 % 00872 % ErrorHandler SetWarningHandler(ErrorHandler handler) 00873 % 00874 % A description of each parameter follows: 00875 % 00876 % o handler: The method to handle warnings. 00877 % 00878 */ 00879 WizardExport WarningHandler SetWarningHandler(WarningHandler handler) 00880 { 00881 WarningHandler 00882 previous_handler; 00883 00884 previous_handler=warning_handler; 00885 warning_handler=handler; 00886 return(previous_handler); 00887 } 00888 00889 /* 00890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00891 % % 00892 % % 00893 % % 00894 % T h r o w E x c e p t i o n % 00895 % % 00896 % % 00897 % % 00898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00899 % 00900 % ThrowException() throws an exception with the specified severity code, 00901 % reason, and optional description. 00902 % 00903 % The format of the ThrowException method is: 00904 % 00905 % WizardBooleanType ThrowException(ExceptionInfo *exception, 00906 % const ExceptionType severity,const char *reason, 00907 % const char *description) 00908 % 00909 % A description of each parameter follows: 00910 % 00911 % o exception: The exception info. 00912 % 00913 % o severity: The severity of the exception. 00914 % 00915 % o reason: The reason for the exception. 00916 % 00917 % o description: The exception description. 00918 % 00919 */ 00920 WizardExport WizardBooleanType ThrowException(ExceptionInfo *exception, 00921 const ExceptionType severity,const char *reason,const char *description) 00922 { 00923 register ExceptionInfo 00924 *p; 00925 00926 assert(exception != (ExceptionInfo *) NULL); 00927 assert(exception->signature == WizardSignature); 00928 if (exception->exceptions == (void *) NULL) 00929 return(WizardTrue); 00930 p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *) 00931 exception->exceptions); 00932 if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) && 00933 (LocaleCompare(exception->reason,reason) == 0) && 00934 (LocaleCompare(exception->description,description) == 0)) 00935 return(WizardTrue); 00936 p=(ExceptionInfo *) AcquireWizardMemory(sizeof(*p)); 00937 if (p == (ExceptionInfo *) NULL) 00938 ThrowFatalException(ResourceFatalError,"memory allocation failed `%s'"); 00939 (void) ResetWizardMemory(p,0,sizeof(*p)); 00940 p->severity=severity; 00941 if (reason != (const char *) NULL) 00942 p->reason=ConstantString(reason); 00943 if (description != (const char *) NULL) 00944 p->description=ConstantString(description); 00945 p->signature=WizardSignature; 00946 (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p); 00947 exception->severity=p->severity; 00948 exception->reason=p->reason; 00949 exception->description=p->description; 00950 return(WizardTrue); 00951 } 00952 00953 /* 00954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00955 % % 00956 % % 00957 % % 00958 % T h r o w W i z a r d E x c e p t i o n % 00959 % % 00960 % % 00961 % % 00962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00963 % 00964 % ThrowWizardException logs an exception as determined by the log configuration 00965 % file. If an error occurs, WizardFalse is returned otherwise WizardTrue. 00966 % 00967 % The format of the ThrowWizardException method is: 00968 % 00969 % WizardBooleanType ThrowWizardException(ExceptionInfo *exception, 00970 % const char *module,const char *function,const size_t line, 00971 % const ExceptionType severity,const char *format,...) 00972 % 00973 % A description of each parameter follows: 00974 % 00975 % o exception: The exception info. 00976 % 00977 % o filename: The source module filename. 00978 % 00979 % o function: The function name. 00980 % 00981 % o line: The line number of the source module. 00982 % 00983 % o severity: Specifies the numeric error category. 00984 % 00985 % o format: The output format. 00986 % 00987 */ 00988 00989 WizardExport WizardBooleanType ThrowWizardExceptionList( 00990 ExceptionInfo *exception,const char *module,const char *function, 00991 const size_t line,const ExceptionType severity,const char *format, 00992 va_list operands) 00993 { 00994 char 00995 message[MaxTextExtent], 00996 reason[MaxTextExtent]; 00997 00998 int 00999 n; 01000 01001 WizardBooleanType 01002 status; 01003 01004 assert(exception != (ExceptionInfo *) NULL); 01005 assert(exception->signature == WizardSignature); 01006 #if defined(WIZARDSTOOLKIT_HAVE_VSNPRINTF) 01007 n=vsnprintf(reason,MaxTextExtent,format,operands); 01008 #else 01009 n=vsprintf(reason,format,operands); 01010 #endif 01011 if (n < 0) 01012 reason[MaxTextExtent-1]='\0'; 01013 status=LogWizardEvent(exception->severity >= ErrorException ? 01014 ExceptionEvent : WarningEvent,module,function,line,"%s",reason); 01015 (void) FormatLocaleString(message,MaxTextExtent,"%s @ %s/%s/%.20g",reason, 01016 module,function,(double) line); 01017 (void) ThrowException(exception,severity,message,(char *) NULL); 01018 return(status); 01019 } 01020 01021 WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, 01022 const char *module,const char *function,const size_t line, 01023 const ExceptionType severity,const char *format,...) 01024 { 01025 WizardBooleanType 01026 status; 01027 01028 va_list 01029 operands; 01030 01031 va_start(operands,format); 01032 status=ThrowWizardExceptionList(exception,module,function,line,severity, 01033 format,operands); 01034 va_end(operands); 01035 return(status); 01036 }