tesseract 5.2.0
Loading...
Searching...
No Matches
tesseract::ERRCODE Class Reference

#include <errcode.h>

Public Member Functions

void error (const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(printf
 
void void error (const char *caller, TessErrorLogCode action) const
 
constexpr ERRCODE (const char *string)
 

Detailed Description

Definition at line 38 of file errcode.h.

Constructor & Destructor Documentation

◆ ERRCODE()

constexpr tesseract::ERRCODE::ERRCODE ( const char *  string)
inlineconstexpr

Definition at line 47 of file errcode.h.

47: message(string) {} // initialize with string

Member Function Documentation

◆ error() [1/2]

void tesseract::ERRCODE::error ( const char *  caller,
TessErrorLogCode  action 
) const

Definition at line 98 of file errcode.cpp.

98 {
99 error(caller, action, nullptr);
100}
void error(const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(printf
Definition: errcode.cpp:38

◆ error() [2/2]

void tesseract::ERRCODE::error ( const char *  caller,
TessErrorLogCode  action,
const char *  format,
  ... 
) const

Definition at line 38 of file errcode.cpp.

42 {
43 va_list args; // variable args
44 char msg[MAX_MSG];
45 char *msgptr = msg;
46
47 if (caller != nullptr) {
48 // name of caller
49 msgptr += sprintf(msgptr, "%s:", caller);
50 }
51 // actual message
52 msgptr += sprintf(msgptr, "Error:%s", message);
53 if (format != nullptr) {
54 msgptr += sprintf(msgptr, ":");
55 va_start(args, format); // variable list
56#ifdef _WIN32
57 // print remainder
58 msgptr += _vsnprintf(msgptr, MAX_MSG - 2 - (msgptr - msg), format, args);
59 msg[MAX_MSG - 2] = '\0'; // ensure termination
60 strcat(msg, "\n");
61#else
62 // print remainder
63 msgptr += vsprintf(msgptr, format, args);
64 // no specific
65 msgptr += sprintf(msgptr, "\n");
66#endif
67 va_end(args);
68 } else {
69 // no specific
70 msgptr += sprintf(msgptr, "\n");
71 }
72
73 // %s is needed here so msg is printed correctly!
74 fprintf(stderr, "%s", msg);
75
76 switch (action) {
77 case DBG:
78 case TESSLOG:
79 return; // report only
80 case TESSEXIT:
81 case ABORT:
82#if !defined(NDEBUG)
83 // Create a deliberate abnormal exit as the stack trace is more useful
84 // that way. This is done only in debug builds, because the
85 // error message "segmentation fault" confuses most normal users.
86# if defined(__GNUC__)
87 __builtin_trap();
88# else
89 *reinterpret_cast<int *>(0) = 0;
90# endif
91#endif
92 abort();
93 default:
94 BADERRACTION.error("error", ABORT);
95 }
96}
#define MAX_MSG
Definition: errcode.cpp:29
constexpr ERRCODE BADERRACTION("Illegal error action")
@ ABORT
Definition: errcode.h:31
@ TESSLOG
Definition: errcode.h:29
@ TESSEXIT
Definition: errcode.h:30

The documentation for this class was generated from the following files: