* error * * Print an error message and continue, exit or abort according to action. * Makes use of error messages and numbers in a common place. * **********************************************************************/
| 38 | * |
| 39 | **********************************************************************/ |
| 40 | void ERRCODE::error( // handle error |
| 41 | const char *caller, // name of caller |
| 42 | TessErrorLogCode action, // action to take |
| 43 | const char *format, ... // special message |
| 44 | ) const { |
| 45 | va_list args; // variable args |
| 46 | char msg[MAX_MSG]; |
| 47 | char *msgptr = msg; |
| 48 | |
| 49 | if (caller != NULL) |
| 50 | //name of caller |
| 51 | msgptr += sprintf (msgptr, "%s:", caller); |
| 52 | //actual message |
| 53 | msgptr += sprintf (msgptr, "Error:%s", message); |
| 54 | if (format != NULL) { |
| 55 | msgptr += sprintf (msgptr, ":"); |
| 56 | va_start(args, format); //variable list |
| 57 | #ifdef _WIN32 |
| 58 | //print remainder |
| 59 | msgptr += _vsnprintf (msgptr, MAX_MSG - 2 - (msgptr - msg), format, args); |
| 60 | msg[MAX_MSG - 2] = '\0'; //ensure termination |
| 61 | strcat (msg, "\n"); |
| 62 | #else |
| 63 | //print remainder |
| 64 | msgptr += vsprintf (msgptr, format, args); |
| 65 | //no specific |
| 66 | msgptr += sprintf (msgptr, "\n"); |
| 67 | #endif |
| 68 | va_end(args); |
| 69 | } |
| 70 | else |
| 71 | //no specific |
| 72 | msgptr += sprintf (msgptr, "\n"); |
| 73 | |
| 74 | // %s is needed here so msg is printed correctly! |
| 75 | fprintf(stderr, "%s", msg); |
| 76 | |
| 77 | int* p = NULL; |
| 78 | switch (action) { |
| 79 | case DBG: |
| 80 | case TESSLOG: |
| 81 | return; //report only |
| 82 | case TESSEXIT: |
| 83 | //err_exit(); |
| 84 | case ABORT: |
| 85 | // Create a deliberate segv as the stack trace is more useful that way. |
| 86 | if (!*p) |
| 87 | abort(); |
| 88 | default: |
| 89 | BADERRACTION.error ("error", ABORT, NULL); |
| 90 | } |
| 91 | } |
no outgoing calls
no test coverage detected