tesseract  4.0.0-1-g2a2b
ERRCODE Class Reference

#include <errcode.h>

Public Member Functions

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

Detailed Description

Definition at line 69 of file errcode.h.

Constructor & Destructor Documentation

◆ ERRCODE()

ERRCODE::ERRCODE ( const char *  string)
inline

Definition at line 77 of file errcode.h.

77  {
78  message = string;
79  } // initialize with string

Member Function Documentation

◆ error()

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

Definition at line 37 of file errcode.cpp.

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

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