/*----------------------------------------------------------------------------* \Module{Error Handling} */ #include #include #include #include "neural.h" #include "protos.h" /*----------------------------------------------------------------------------* \Section{Handle Fatal Error} [The following paragraph(s) should be worked into a description at the very top of this module.] When the program encounters a fatal error, it can choose to exit directly to the operating system, rather than propagate the error back up to higher levels. This non-graceful, panic-like system of exiting was chosen for two reasons: (1) it is much simpler than a graceful method, and (2) graceful methods are of no particular benefit in this program. For example, if a memory allocation routine always calls this routine upon failure, it can guarantee the caller that a valid memory pointer will always be returned so that the caller need not check the validity of the pointer. This convention may seem a bit sophomoric, but the decision to use this method was made carefully, and in the grand scheme of things the author believes it is the right choice. After all, this is a scientific program, not a word processor. If any files are open upon entry to this routine, they will be closed by the operating system. Any allocated memory will also be released. \ENTRY: 'fmt' points to a format string in the manner of 'printf'. Other items on the stack are parameters. \EXIT: This function does not return. //void cdecl FatalError (char *fmt, ...) //{ // va_list args; // Obtain a pointer to the variable // va_start(args, fmt); // length argument list. // // vprintf(fmt, args); // Write the string to the standard // exit(255); // output device and bail. //} /*----------------------------------------------------------------------------* \Section{General Assertion} General assertions that fail are sent here to be reported to the programmer (hopefully not to the user!) with the 'FatalError' funtion. This routine will not return to the caller. This routine is never called directly, but instead is called by the 'assert' macro in the event of assertion failure (see the '.h' file). \ENTRY: 'file' is the name of the file containing the assertion. 'line' is the line number of the assertion. 'expr' is the expression itself. \EXIT: This function does not return. */ void AssertFunc (char *file, int line, char *expr) { // FatalError("Assertion failure: %s(%d) \"%s\"\n", file, line, expr); printf("Assertion failure: %s(%d) \"%s\"\n", file, line, expr); exit(255); }