tesseract v5.3.3.20231005
tesseract::ERRCODE Class Reference

#include <errcode.h>

Public Member Functions

void error (const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(gnu_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 89 of file errcode.cpp.

89 {
90 error(caller, action, nullptr);
91}
action
Definition: upload.py:408
void error(const char *caller, TessErrorLogCode action, const char *format,...) const __attribute__((format(gnu_printf
Definition: errcode.cpp:40

◆ error() [2/2]

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

Definition at line 40 of file errcode.cpp.

44 {
45 va_list args; // variable args
46 std::stringstream msg;
47
48 if (caller != nullptr) {
49 // name of caller
50 msg << caller << ':';
51 }
52 // actual message
53 msg << "Error:" << message;
54 if (format != nullptr) {
55 char str[MAX_MSG];
56 va_start(args, format); // variable list
57 // print remainder
58 std::vsnprintf(str, sizeof(str), format, args);
59 // ensure termination
60 str[sizeof(str) - 1] = '\0';
61 va_end(args);
62 msg << ':' << str;
63 }
64
65 std::cerr << msg.str() << '\n';
66
67 switch (action) {
68 case DBG:
69 case TESSLOG:
70 return; // report only
71 case TESSEXIT:
72 case ABORT:
73#if !defined(NDEBUG)
74 // Create a deliberate abnormal exit as the stack trace is more useful
75 // that way. This is done only in debug builds, because the
76 // error message "segmentation fault" confuses most normal users.
77# if defined(__GNUC__)
78 __builtin_trap();
79# else
80 *reinterpret_cast<int *>(0) = 0;
81# endif
82#endif
83 abort();
84 default:
85 BADERRACTION.error("error", ABORT);
86 }
87}
#define MAX_MSG
Definition: errcode.cpp:31
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: