tesseract  5.0.0-alpha-619-ge9db
ERRCODE Class Reference

#include <errcode.h>

Public Member Functions

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

Detailed Description

Definition at line 67 of file errcode.h.

Constructor & Destructor Documentation

◆ ERRCODE()

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

Definition at line 75 of file errcode.h.

76  : message(string) {

Member Function Documentation

◆ error()

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

Definition at line 33 of file errcode.cpp.

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

The documentation for this class was generated from the following files:
MAX_MSG
#define MAX_MSG
Definition: errcode.cpp:25
TESSEXIT
Definition: errcode.h:42
BADERRACTION
constexpr ERRCODE BADERRACTION("Illegal error action")
TESSLOG
Definition: errcode.h:41
ERRCODE::error
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:33
ABORT
Definition: errcode.h:43
DBG
Definition: errcode.h:40
tesstrain_utils.action
action
Definition: tesstrain_utils.py:159