NCBI C++ ToolKit
ncbiexpt.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbiexpt.cpp 89615 2020-04-10 11:36:43Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Denis Vakatov, Andrei Gourianov,
27  * Eugene Vasilchenko, Anton Lavrentiev
28  *
29  * File Description:
30  * CException
31  * CExceptionReporter
32  * CExceptionReporterStream
33  * CErrnoException
34  * CParseException
35  * + initialization for the "unexpected"
36  *
37  */
38 
39 #include <ncbi_pch.hpp>
40 #include <corelib/ncbiexpt.hpp>
41 #include <corelib/ncbithr.hpp>
43 #include <corelib/ncbi_param.hpp>
44 #include <corelib/request_ctx.hpp>
45 #include <corelib/error_codes.hpp>
46 #include "ncbisys.hpp"
47 #include <errno.h>
48 #include <string.h>
49 #include <stdio.h>
50 #include <stack>
51 #include <atomic>
52 
53 
54 #define NCBI_USE_ERRCODE_X Corelib_Diag
55 
56 
58 
59 /////////////////////////////////
60 // SetThrowTraceAbort
61 // DoThrowTraceAbort
62 
63 static atomic<bool> s_DoThrowTraceAbort(false); //if to abort() in DoThrowTraceAbort()
64 static atomic<bool> s_DTTA_Initialized(false); //if s_DoThrowTraceAbort is init'd
65 
66 extern void SetThrowTraceAbort(bool abort_on_throw_trace)
67 {
68  s_DTTA_Initialized = true;
69  s_DoThrowTraceAbort = abort_on_throw_trace;
70 }
71 
72 extern void DoThrowTraceAbort(void)
73 {
74  if ( !s_DTTA_Initialized ) {
76  if (str && *str)
77  s_DoThrowTraceAbort = true;
78  s_DTTA_Initialized = true;
79  }
80 
81  if ( s_DoThrowTraceAbort )
82  abort();
83 }
84 
85 
86 extern void DoDbgPrint(const CDiagCompileInfo &info, const char* message)
87 {
88  CNcbiDiag(info, eDiag_Trace) << message;
90 }
91 
92 extern void DoDbgPrint(const CDiagCompileInfo &info, const string& message)
93 {
94  CNcbiDiag(info, eDiag_Trace) << message;
96 }
97 
98 extern void DoDbgPrint(const CDiagCompileInfo &info,
99  const char* msg1, const char* msg2)
100 {
101  CNcbiDiag(info, eDiag_Trace) << msg1 << ": " << msg2;
103 }
104 
105 
106 /////////////////////////////////////////////////////////////////////////////
107 // Stack trace control
108 
109 NCBI_PARAM_ENUM_ARRAY(EDiagSev, EXCEPTION, Stack_Trace_Level)
110 {
111  {"Trace", eDiag_Trace},
112  {"Info", eDiag_Info},
113  {"Warning", eDiag_Warning},
114  {"Error", eDiag_Error},
115  {"Critical", eDiag_Critical},
116  {"Fatal", eDiag_Fatal}
117 };
118 
119 
120 NCBI_PARAM_ENUM_DECL(EDiagSev, EXCEPTION, Stack_Trace_Level);
122  EXCEPTION,
123  Stack_Trace_Level,
125  eParam_NoThread, // No per-thread values
126  EXCEPTION_STACK_TRACE_LEVEL);
127 typedef NCBI_PARAM_TYPE(EXCEPTION, Stack_Trace_Level) TStackTraceLevelParam;
128 
130 {
131  TStackTraceLevelParam::SetDefault(level);
132 }
133 
134 
136 {
137  return TStackTraceLevelParam::GetDefault();
138 }
139 
140 
141 NCBI_PARAM_DECL(bool, EXCEPTION, Abort_If_Critical);
143  EXCEPTION,
144  Abort_If_Critical,
145  false,
147  EXCEPTION_ABORT_IF_CRITICAL);
148 typedef NCBI_PARAM_TYPE(EXCEPTION, Abort_If_Critical) TAbortIfCritical;
149 
151 
152 
154 {
155 public:
158 private:
160 };
161 
162 
163 /////////////////////////////////////////////////////////////////////////////
164 // CException implementation
165 
166 bool CException::sm_BkgrEnabled = false;
167 
168 
170  const CException* prev_exception,
171  EErrCode err_code,
172  const string& message,
173  EDiagSev severity,
174  TFlags flags)
175 : m_Severity(severity),
176  m_ErrCode(err_code),
177  m_Predecessor(0),
178  m_InReporter(false),
179  m_MainText(true),
180  m_Flags(flags),
181  m_Retriable(eRetriable_Unknown)
182 {
183  if (CompareDiagPostLevel(severity, eDiag_Critical) >= 0 &&
184  s_AbortIfCritical->Get()) {
185  abort();
186  }
187  x_Init(info, message, prev_exception, severity);
188  if (prev_exception)
189  prev_exception->m_MainText = false;
190 }
191 
193  const CException* prev_exception,
194  const string& message,
195  EDiagSev severity,
196  TFlags flags)
197 : m_Severity(severity),
198  m_ErrCode(CException::eInvalid),
199  m_Predecessor(0),
200  m_InReporter(false),
201  m_MainText(true),
202  m_Flags(flags),
203  m_Retriable(eRetriable_Unknown)
204 {
205  if (CompareDiagPostLevel(severity, eDiag_Critical) >= 0 &&
206  s_AbortIfCritical->Get()) {
207  abort();
208  }
209  x_Init(info, message, prev_exception, severity);
210  if (prev_exception)
211  prev_exception->m_MainText = false;
212 }
213 
215  const CException* prev_exception,
216  const CExceptionArgs<EErrCode>& args,
217  const string& message)
218 : m_Severity(args.GetSeverity()),
219  m_ErrCode(args.GetErrCode()),
220  m_Predecessor(0),
221  m_InReporter(false),
222  m_MainText(true),
223  m_Flags(args.GetFlags()),
224  m_Retriable(eRetriable_Unknown)
225 {
227  s_AbortIfCritical->Get()) {
228  abort();
229  }
230  x_Init(info, message, prev_exception, m_Severity);
231  x_InitArgs(args);
232 
233  if (prev_exception)
234  prev_exception->m_MainText = false;
235 }
236 
237 
239 : m_Predecessor(0)
240 {
241  x_Assign(other);
242 }
243 
245 : m_Severity(eDiag_Error),
246  m_Line(-1),
247  m_ErrCode(CException::eInvalid),
248  m_Predecessor(0),
249  m_InReporter(false),
250  m_MainText(true),
251  m_Flags(0),
252  m_Retriable(eRetriable_Unknown),
253  m_RequestContext(new CRequestContextRef(GetDiagContext().GetRequestContext()))
254 {
255 // this only is called in case of multiple inheritance
256 }
257 
258 
260 {
261  if (m_Predecessor) {
262  delete m_Predecessor;
263  m_Predecessor = 0;
264  }
265 }
266 
267 
268 const char* CException::GetType(void) const
269 {
270  return "CException";
271 }
272 
273 
275  const string& message,
276  EDiagSev severity)
277 {
278  const CException* prev = m_Predecessor;
280  if (prev) {
281  delete prev;
282  }
283  x_Init(info, message, 0, severity);
284  m_MainText = false;
285 }
286 
287 
288 void CException::AddToMessage(const string& add_msg)
289 {
290  if (add_msg.empty()) {
291  return;
292  }
293 
294  if (m_Msg.empty() && m_Predecessor != NULL) {
296  }
297  m_Msg += add_msg;
298 }
299 
300 
301 void CException::AddPrevious(const CException* prev_exception)
302 {
303  if (m_Predecessor) {
304  const CException* prev = m_Predecessor;
305  const CException* next = prev->m_Predecessor;
306  while (next) {
307  prev = next;
308  next = prev->m_Predecessor;
309  }
310  prev->m_Predecessor = prev_exception->x_Clone();
311  }
312  else {
313  m_Predecessor = prev_exception->x_Clone();
314  }
315 
316  for (const CException* pex = prev_exception; pex; pex = pex->m_Predecessor)
317  pex->m_MainText = false;
318 }
319 
320 
322 {
323  if (CompareDiagPostLevel(severity, eDiag_Critical) >= 0 &&
324  s_AbortIfCritical->Get()) {
325  abort();
326  }
327  m_Severity = severity;
328  x_GetStackTrace(); // May need stack trace with the new severity
329  return *this;
330 }
331 
332 
333 void CException::Throw(void) const
334 {
335  x_ThrowSanityCheck(typeid(CException), "CException");
336  throw *this;
337 }
338 
339 
340 // ---- report --------------
341 
342 const char* CException::what(void) const throw()
343 {
344  m_What = ReportAll();
345  if ( m_StackTrace.get() && !m_StackTrace->Empty() ) {
346  CNcbiOstrstream os;
347  string old_prefix = m_StackTrace->GetPrefix();
348  m_StackTrace->SetPrefix(" ");
349  os << " Stack trace:\n" << *m_StackTrace;
350  m_StackTrace->SetPrefix(old_prefix);
351  m_What += (string) CNcbiOstrstreamToString(os);
352  }
353  return m_What.c_str();
354 }
355 
356 
358  const string& title,CExceptionReporter* reporter,
359  TDiagPostFlags flags) const
360 {
361  if (reporter) {
362  reporter->Report(info.GetFile(), info.GetLine(), title, *this, flags);
363  }
364  // unconditionally ...
365  // that is, there will be two reports
367 }
368 
369 
371 {
372  // invert the order
373  stack<const CException*> pile;
374  const CException* pex;
375  for (pex = this; pex; pex = pex->GetPredecessor()) {
376  pile.push(pex);
377  }
378  CNcbiOstrstream os;
379  os << "NCBI C++ Exception:" << '\n';
380  for (; !pile.empty(); pile.pop()) {
381  //indentation
382  os << " ";
383  os << pile.top()->ReportThis(flags) << '\n';
384  }
385  if (sm_BkgrEnabled && !m_InReporter) {
386  m_InReporter = true;
389  "(background reporting)",
390  *this, eDPF_Exception);
391  m_InReporter = false;
392  }
393  return CNcbiOstrstreamToString(os);
394 }
395 
396 
398 {
399  CNcbiOstrstream os, osex;
400  ReportStd(os, flags);
401  ReportExtra(osex);
402  if ( !IsOssEmpty(osex) ) {
403  os << " (" << (string)CNcbiOstrstreamToString(osex) << ')';
404  }
405  return CNcbiOstrstreamToString(os);
406 }
407 
408 
410 {
411  string text(GetMsg());
412  string err_type(GetType());
413  err_type += "::";
414  err_type += GetErrCodeString();
415  SDiagMessage diagmsg(
416  GetSeverity(),
417  text.c_str(),
418  text.size(),
419  GetFile().c_str(),
420  GetLine(),
421  flags, NULL, 0, 0, err_type.c_str(),
422  GetModule().c_str(),
423  GetClass().c_str(),
424  GetFunction().c_str());
426 }
427 
428 void CException::ReportExtra(ostream& /*out*/) const
429 {
430  return;
431 }
432 
433 
435 {
436  if (!m_StackTrace.get() || m_StackTrace->Empty() ||
438  return NULL;
439  }
440  return m_StackTrace.get();
441 }
442 
443 
444 const char* CException::GetErrCodeString(void) const
445 {
446  switch (GetErrCode()) {
447  case eUnknown: return "eUnknown";
448  default: return "eInvalid";
449  }
450 }
451 
452 
454 {
455  return typeid(*this) == typeid(CException) ?
456  (TErrCode) x_GetErrCode() :
458 }
459 
460 
461 const string& CException::GetMsg(void) const
462 {
463  for (const CException* ex = this; ex != NULL; ex = ex->m_Predecessor) {
464  if ( !ex->m_Msg.empty() ) {
465  return ex->m_Msg;
466  }
467  }
468  return kEmptyStr;
469 }
470 
471 
473 {
474  return m_RequestContext->GetRequestContext();
475 }
476 
477 
479 {
480 #if defined(NCBI_OS_MSWIN) && defined(_DEBUG)
481  // On MS Windows print out reported information into debug output window
482  CNcbiOstrstream os;
483  os << "NCBI C++ Exception:" << '\n';
484  os <<
485  GetFile() << "(" << GetLine() << ") : " <<
486  GetType() << "::" << GetErrCodeString() << " : \"" <<
487  GetMsg() << "\" ";
488  ReportExtra(os);
489  os << '\n';
490  ::OutputDebugStringA(((string)CNcbiOstrstreamToString(os)).c_str());
491 #endif
493 }
494 
495 
497 {
498  bool prev = sm_BkgrEnabled;
499  sm_BkgrEnabled = enable;
500  return prev;
501 }
502 
503 const CException* CException::x_Clone(void) const
504 {
505  return new CException(*this);
506 }
507 
508 
509 void CException::x_Init(const CDiagCompileInfo& info,const string& message,
510  const CException* prev_exception, EDiagSev severity)
511 {
512  m_Severity = severity;
513  m_File = info.GetFile();
514  m_Line = info.GetLine();
515  m_Module = info.GetModule();
516  m_Class = info.GetClass();
517  m_Function = info.GetFunction();
518  m_Msg = message;
519  if (!m_Predecessor && prev_exception) {
520  m_Predecessor = prev_exception->x_Clone();
521  }
523  x_GetStackTrace();
524 }
525 
526 
528 {
529  if ( args.IsSetModule() ) {
530  m_Module = args.GetModule();
531  }
532  m_Retriable = args.GetRetriable();
533 }
534 
535 
537 {
538  m_Severity = src.m_Severity;
539  m_InReporter = false;
540  m_MainText = src.m_MainText;
541  m_File = src.m_File;
542  m_Line = src.m_Line;
543  m_Msg = src.m_Msg;
544  x_AssignErrCode(src);
545  m_Module = src.m_Module;
546  m_Class = src.m_Class;
547  m_Function = src.m_Function;
548  if (!m_Predecessor && src.m_Predecessor) {
550  }
551  if ( src.m_StackTrace.get() ) {
552  m_StackTrace.reset(new CStackTrace(*src.m_StackTrace));
553  }
554  m_Flags = src.m_Flags;
555  m_Retriable = src.m_Retriable;
556  m_RequestContext.reset(new CRequestContextRef(src.m_RequestContext->GetRequestContext()));
557 }
558 
559 
561 {
562  m_ErrCode = typeid(*this) == typeid(src) ?
564 }
565 
566 
568 {
569  m_ErrCode = err_code;
570  if (m_ErrCode != eInvalid && !m_Predecessor) {
572  }
573 }
574 
575 
577 {
578  if ( m_StackTrace.get() ) {
579  return;
580  }
582  return;
583  }
584  m_StackTrace.reset(new CStackTrace);
585 }
586 
587 
589  const char* human_name) const
590 {
591  const type_info& actual_type = typeid(*this);
592  if (actual_type != expected_type) {
593  ERR_POST_X(14, Warning << "CException::Throw(): throwing object of type "
594  << actual_type.name() << " as " << expected_type.name()
595  << " [" << human_name << ']');
596  }
597 }
598 
599 
600 /////////////////////////////////////////////////////////////////////////////
601 // CExceptionReporter
602 
604 
606 
607 
609 {
610  return;
611 }
612 
613 
615 {
616  return;
617 }
618 
619 
621 {
623 }
624 
625 
627 {
628  return sm_DefHandler;
629 }
630 
631 
633 {
634  bool prev = sm_DefEnabled;
635  sm_DefEnabled = enable;
636  return prev;
637 }
638 
639 
641 {
642 public:
644  const exception& ex);
645 
646  virtual const char* GetErrCodeString(void) const;
647  virtual const char* GetType(void) const;
648 };
649 
650 
652  const exception& ex)
653  : CException(info, NULL, eUnknown, ex.what())
654 {
655 }
656 
657 
658 const char* CExceptionWrapper::GetErrCodeString(void) const
659 {
660  return kEmptyCStr;
661 }
662 
663 
664 const char* CExceptionWrapper::GetType(void) const
665 {
666  return "exception";
667 }
668 
669 
671  const string& title,const exception& ex, TDiagPostFlags flags)
672 {
673  ReportDefaultEx(0, 0, info, title, ex, flags);
674 }
675 
676 void CExceptionReporter::ReportDefaultEx(int err_code, int err_subcode,
677  const CDiagCompileInfo& info, const string& title,const exception& ex,
679 {
680  if ( !sm_DefEnabled )
681  return;
682 
683  const CException* cex = dynamic_cast<const CException*>(&ex);
684  unique_ptr<CException> wrapper;
685  if ( !cex ) {
686  wrapper.reset(new CExceptionWrapper(info, ex));
687  cex = wrapper.get();
688  }
689  if ( sm_DefHandler ) {
690  sm_DefHandler->Report(info.GetFile(),
691  info.GetLine(),
692  title,
693  *cex,
694  flags);
695  } else {
696  CNcbiDiag d(info, cex->GetSeverity(), flags);
697  d.SetOmitStackTrace(true);
698  d << ErrCode(err_code, err_subcode) << title << " " << *cex;
699  }
700 }
701 
702 
703 /////////////////////////////////////////////////////////////////////////////
704 // CExceptionReporterStream
705 
706 
708  : m_Out(out)
709 {
710  return;
711 }
712 
713 
715 {
716  return;
717 }
718 
719 
720 void CExceptionReporterStream::Report(const char* file, int line,
721  const string& title, const CException& ex, TDiagPostFlags flags) const
722 {
723  SDiagMessage diagmsg(ex.GetSeverity(),
724  title.c_str(),
725  title.size(),
726  file,
727  line,
728  flags,
729  NULL,
730  0, 0,
731  ex.GetModule().c_str(),
732  ex.GetClass().c_str(),
733  ex.GetFunction().c_str());
734  diagmsg.Write(m_Out);
735 
736  m_Out << "NCBI C++ Exception:" << endl;
737  // invert the order
738  stack<const CException*> pile;
739  const CException* pex;
740  for (pex = &ex; pex; pex = pex->GetPredecessor()) {
741  pile.push(pex);
742  }
743  for (; !pile.empty(); pile.pop()) {
744  pex = pile.top();
745  m_Out << " ";
746  m_Out << pex->ReportThis(flags) << endl;
747  }
748 }
749 
750 
751 
752 /////////////////////////////////////////////////////////////////////////////
753 // Core exceptions
754 /////////////////////////////////////////////////////////////////////////////
755 
756 
757 const char* CCoreException::GetErrCodeString(void) const
758 {
759  switch (GetErrCode()) {
760  case eCore: return "eCore";
761  case eNullPtr: return "eNullPtr";
762  case eDll: return "eDll";
763  case eDiagFilter: return "eDiagFilter";
764  case eInvalidArg: return "eInvalidArg";
765  default: return CException::GetErrCodeString();
766  }
767 }
768 
769 
771 {
772  switch (GetErrCode()) {
773  case eUndefined: return "eUndefined";
774  case eInvalidCharacter: return "eInvalidCharacter";
775  default: return CException::GetErrCodeString();
776  }
777 }
778 
779 
780 
781 #if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
782  (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
783 // MT: Store pointer to the strerror message in TLS
784 static CStaticTls<char> s_TlsStrerrorMessage;
785 static void s_TlsStrerrorMessageCleanup(char* msg, void* /* data */)
786 {
787  delete [] msg;
788 }
789 #endif
790 
791 
792 
793 extern const char* Ncbi_strerror(int errnum)
794 {
795 #if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
796  (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
797  string tmp;
798 # if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__
799  TXChar xbuf[256];
800  NcbiSys_strerror_s(xbuf,sizeof(xbuf)/sizeof(TXChar),errnum);
801  tmp = _T_STDSTRING(xbuf);
802 # else
803  tmp = _T_STDSTRING( NcbiSys_strerror(errnum) );
804 # endif
805  char* ptr = new char[ tmp.size() + 1];
806  strcpy(ptr, tmp.c_str());
807  s_TlsStrerrorMessage.SetValue(ptr, s_TlsStrerrorMessageCleanup);
808  return ptr;
809 #else
810  return NcbiSys_strerror(errnum);
811 #endif
812 }
813 
814 
815 
816 #if defined(NCBI_OS_MSWIN)
817 
818 // MT: Store pointer to the last error message in TLS
820 static void s_TlsErrorMessageCleanup(char* msg, void* /* data */)
821 {
822  LocalFree(msg);
823 }
824 
825 
826 const char* CLastErrorAdapt::GetErrCodeString(int errnum)
827 {
828  TXChar* xptr = NULL;
829  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
830  FORMAT_MESSAGE_FROM_SYSTEM |
831  FORMAT_MESSAGE_MAX_WIDTH_MASK |
832  FORMAT_MESSAGE_IGNORE_INSERTS,
833  "%0", errnum,
834  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
835  (TXChar*)&xptr, 0, NULL);
836 #if defined(_UNICODE)
837  CStringUTF8 tmp( CUtf8::AsUTF8(xptr));
838  char* ptr = (char*) LocalAlloc(LPTR, tmp.size() + 1);
839  strcpy(ptr, tmp.c_str());
840  LocalFree(xptr);
841 #else
842  char* ptr = xptr;
843 #endif
844  // Remove trailing dots and spaces
845  size_t pos = strlen(ptr);
846  if ( pos ) {
847  while (--pos && (ptr[pos] == '.' || ptr[pos] == ' ')) {
848  ptr[pos] = '\0';
849  }
850  }
851  // Save pointer
853  return ptr;
854 }
855 
856 #endif
857 
858 
859 
860 // Function declared in ncbimics.hpp
861 void g_ThrowOnNull(void)
862 {
863  NCBI_THROW(CCoreException, eNullPtr,
864  "Attempt to access NULL CNullable value.");
865 }
866 
867 
CCoreException –.
Definition: ncbiexpt.hpp:1476
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
Definition: ncbidiag.hpp:65
CExceptionReporter –.
Definition: ncbiexpt.hpp:1399
virtual const char * GetType(void) const
Definition: ncbiexpt.cpp:664
virtual const char * GetErrCodeString(void) const
Definition: ncbiexpt.cpp:658
CExceptionWrapper(const CDiagCompileInfo &info, const exception &ex)
Definition: ncbiexpt.cpp:651
CNcbiDiag –.
Definition: ncbidiag.hpp:924
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CRequestContext & GetRequestContext(void)
Definition: ncbiexpt.cpp:157
CRequestContextRef(CRequestContext &ctx)
Definition: ncbiexpt.cpp:156
CRef< CRequestContext > m_Context
Definition: ncbiexpt.cpp:159
CSafeStatic<>::
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
CS_CONTEXT * ctx
Definition: t0006.c:12
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
static const char * str(char *buf, int n)
Definition: stats.c:84
static char expected_type[20]
Definition: tables.c:56
static char tmp[3200]
Definition: utf8.c:42
void g_ThrowOnNull(void)
Definition: ncbiexpt.cpp:861
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
Definition: ncbimisc.hpp:169
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
void Write(string &str, TDiagWriteFlags flags=fNone) const
Binary OR of "EDiagWriteFlags".
Definition: ncbidiag.cpp:5358
CDiagContext & GetDiagContext(void)
Get diag context instance.
Definition: logging.cpp:818
int TDiagPostFlags
Binary OR of "EDiagPostFlag".
Definition: ncbidiag.hpp:785
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
int CompareDiagPostLevel(EDiagSev sev1, EDiagSev sev2)
Compare two severities.
Definition: ncbidiag.cpp:6160
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
void SetOmitStackTrace(bool value)
Definition: ncbidiag.hpp:1200
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDPF_Exception
Default flags to use for exception formatting.
Definition: ncbidiag.hpp:744
@ fNoEndl
No end of line.
Definition: ncbidiag.hpp:1704
@ fNoPrefix
No std prefix.
Definition: ncbidiag.hpp:1705
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
@ eDiag_Critical
Critical error message.
Definition: ncbidiag.hpp:654
bool m_MainText
Exception has main text.
Definition: ncbiexpt.hpp:1129
virtual ~CExceptionReporterStream(void)
Destructor.
Definition: ncbiexpt.cpp:714
string m_File
File to report on.
Definition: ncbiexpt.hpp:1116
const string & GetModule(void) const
Get module name used for reporting.
Definition: ncbiexpt.hpp:1017
const char * Ncbi_strerror(int errnum)
Definition: ncbiexpt.cpp:793
void AddPrevious(const CException *prev_exception)
Definition: ncbiexpt.cpp:301
virtual void ReportExtra(ostream &out) const
Report "non-standard" attributes.
Definition: ncbiexpt.cpp:428
static void SetDefault(const CExceptionReporter *handler)
Set default reporter.
Definition: ncbiexpt.cpp:620
void x_GetStackTrace(void)
Get and store current stack trace.
Definition: ncbiexpt.cpp:576
virtual const char * GetType(void) const
Get class name as a string.
Definition: ncbiexpt.cpp:268
void Report(const CDiagCompileInfo &info, const string &title, CExceptionReporter *reporter=0, TDiagPostFlags flags=eDPF_Exception) const
Report the exception.
Definition: ncbiexpt.cpp:357
static const char * GetErrCodeString(int errnum)
Definition: ncbiexpt.cpp:826
bool IsSetModule(void) const
Definition: ncbiexpt.hpp:804
ERetriable GetRetriable(void) const
Definition: ncbiexpt.hpp:807
static void ReportDefaultEx(int err_code, int err_subcode, const CDiagCompileInfo &info, const string &title, const std::exception &ex, TDiagPostFlags flags=eDPF_Exception)
Report exception using default reporter and particular error code and subcode when writing to diagnos...
Definition: ncbiexpt.cpp:676
static const CExceptionReporter * sm_DefHandler
Default handler.
Definition: ncbiexpt.hpp:1436
virtual void Throw(void) const
Polymorphically (re)throw an exception whose exact type is uncertain.
Definition: ncbiexpt.cpp:333
TFlags m_Flags
Flags, hints, attributes.
Definition: ncbiexpt.hpp:1134
TExceptionPtr m_Predecessor
Previous exception.
Definition: ncbiexpt.hpp:1126
const string & GetFile(void) const
Get file name used for reporting.
Definition: ncbiexpt.hpp:1011
void DoThrowTraceAbort(void)
"abort()" the program if set by SetThrowTraceAbort() or $ABORT_ON_THROW.
Definition: ncbiexpt.cpp:72
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
static void ReportDefault(const CDiagCompileInfo &info, const string &title, const std::exception &ex, TDiagPostFlags flags=eDPF_Exception)
Report exception using default reporter.
Definition: ncbiexpt.cpp:670
virtual int x_GetErrCode(void) const
Helper method for getting error code.
Definition: ncbiexpt.hpp:1105
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
virtual ~CException(void) noexcept
Destructor.
Definition: ncbiexpt.cpp:259
virtual void Report(const char *file, int line, const string &title, const CException &ex, TDiagPostFlags flags=eDPF_Exception) const
Report specified exception on output stream.
Definition: ncbiexpt.cpp:720
ERetriable m_Retriable
In some cases it is known for sure if an action caused the exception can be tried again or not.
Definition: ncbiexpt.hpp:1136
ostream & m_Out
Output stream.
Definition: ncbiexpt.hpp:1462
CExceptionReporter(void)
Constructor.
Definition: ncbiexpt.cpp:608
static bool sm_DefEnabled
Default enable flag.
Definition: ncbiexpt.hpp:1437
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
static bool EnableDefault(bool enable)
Enable/disable using default reporter.
Definition: ncbiexpt.cpp:632
static const CExceptionReporter * GetDefault(void)
Get default reporter.
Definition: ncbiexpt.cpp:626
CRequestContext & GetRequestContext(void) const
Get the request context in which the exception was thrown.
Definition: ncbiexpt.cpp:472
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
virtual void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity)
Helper method for initializing exception data.
Definition: ncbiexpt.cpp:509
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
string m_Function
Function to report on.
Definition: ncbiexpt.hpp:1122
virtual void x_InitErrCode(CException::EErrCode err_code)
Helper method for initializing error code.
Definition: ncbiexpt.cpp:567
virtual void x_Assign(const CException &src)
Helper method for copying exception data.
Definition: ncbiexpt.cpp:536
void ReportStd(ostream &out, TDiagPostFlags flags=eDPF_Exception) const
Report "standard" attributes.
Definition: ncbiexpt.cpp:409
CExceptionReporterStream(ostream &out)
Constructor.
Definition: ncbiexpt.cpp:707
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
Definition: ncbiexpt.cpp:757
int TErrCode
Definition: ncbiexpt.hpp:889
virtual void Report(const char *file, int line, const string &title, const CException &ex, TDiagPostFlags flags=eDPF_Exception) const =0
Report CException with _this_ reporter.
static bool EnableBackgroundReporting(bool enable)
Enable background reporting.
Definition: ncbiexpt.cpp:496
void AddToMessage(const string &add_msg)
Definition: ncbiexpt.cpp:288
EDiagSev m_Severity
Severity level for the exception.
Definition: ncbiexpt.hpp:1115
string m_Module
Module to report on.
Definition: ncbiexpt.hpp:1120
const string & GetClass(void) const
Get class name used for reporting.
Definition: ncbiexpt.hpp:1023
virtual const CException * x_Clone(void) const
Helper method for cloning the exception.
Definition: ncbiexpt.cpp:503
#define ABORT_ON_THROW
ABORT_ON_THROW controls if program should be aborted.
Definition: ncbiexpt.hpp:80
unique_ptr< CStackTrace > m_StackTrace
Saved stack trace.
Definition: ncbiexpt.hpp:1132
static EDiagSev GetStackTraceLevel(void)
Get current severity level for saving and printing stack trace.
Definition: ncbiexpt.cpp:135
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
TErrCode GetErrCode(void) const
Definition: ncbiexpt.hpp:1493
string ReportThis(TDiagPostFlags flags=eDPF_Exception) const
Report this exception only.
Definition: ncbiexpt.cpp:397
const string & GetModule(void) const
Definition: ncbiexpt.hpp:803
virtual const char * GetErrCodeString(void) const override
Translate from an error code value to its string representation.
Definition: ncbiexpt.cpp:770
virtual void x_AssignErrCode(const CException &src)
Helper method for assigning error code.
Definition: ncbiexpt.cpp:560
const string & GetFunction(void) const
Get function name used for reporting.
Definition: ncbiexpt.hpp:1029
unique_ptr< CRequestContextRef > m_RequestContext
Definition: ncbiexpt.hpp:1141
void DoDbgPrint(const CDiagCompileInfo &info, const char *message)
Print the specified debug message.
Definition: ncbiexpt.cpp:86
EDiagSev GetSeverity(void) const
Get exception severity.
Definition: ncbiexpt.hpp:999
CException & SetSeverity(EDiagSev severity)
Set exception severity.
Definition: ncbiexpt.cpp:321
virtual ~CExceptionReporter(void)
Destructor.
Definition: ncbiexpt.cpp:614
void x_ThrowSanityCheck(const type_info &expected_type, const char *human_name) const
Warn if Throw() will end up slicing its invocant.
Definition: ncbiexpt.cpp:588
virtual void x_ReportToDebugger(void) const
Helper method for reporting to the system debugger.
Definition: ncbiexpt.cpp:478
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
static bool sm_BkgrEnabled
Background reporting enabled flag.
Definition: ncbiexpt.hpp:1130
string m_Class
Class to report on.
Definition: ncbiexpt.hpp:1121
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
void AddBacklog(const CDiagCompileInfo &info, const string &message, EDiagSev severity=eDiag_Error)
Add a message to backlog (to re-throw the same exception then).
Definition: ncbiexpt.cpp:274
int GetLine(void) const
Get line number where error occurred.
Definition: ncbiexpt.hpp:1032
bool m_InReporter
Reporter flag.
Definition: ncbiexpt.hpp:1128
int m_Line
Line number.
Definition: ncbiexpt.hpp:1117
int m_ErrCode
Error code.
Definition: ncbiexpt.hpp:1118
virtual void x_InitArgs(const CExceptionArgs_Base &args)
Process additional arguments.
Definition: ncbiexpt.cpp:527
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
Definition: ncbiexpt.hpp:1388
static void SetStackTraceLevel(EDiagSev level)
Set severity level for saving and printing stack trace.
Definition: ncbiexpt.cpp:129
void SetThrowTraceAbort(bool abort_on_throw_trace)
Specify whether to call "abort()" inside the DoThrowTraceAbort().
Definition: ncbiexpt.cpp:66
string m_Msg
Message string.
Definition: ncbiexpt.hpp:1119
const CException * GetPredecessor(void) const
Get "previous" exception from the backlog.
Definition: ncbiexpt.hpp:1041
CException(void)
Constructor with no arguments.
Definition: ncbiexpt.cpp:244
const CStackTrace * GetStackTrace(void) const
Get the saved stack trace if available or NULL.
Definition: ncbiexpt.cpp:434
TErrCode GetErrCode(void) const
Definition: ncbiexpt.hpp:1516
@ eCore
Generic corelib error.
Definition: ncbiexpt.hpp:1482
@ eDll
Dll error.
Definition: ncbiexpt.hpp:1484
@ eDiagFilter
Illegal syntax of the diagnostics filter string.
Definition: ncbiexpt.hpp:1485
@ eNullPtr
Null pointer error.
Definition: ncbiexpt.hpp:1483
@ eInvalidArg
Invalid argument error.
Definition: ncbiexpt.hpp:1486
@ eInvalid
To be used ONLY as a return value; please, NEVER throw an exception with this code.
Definition: ncbiexpt.hpp:885
@ eUnknown
Unknown exception.
Definition: ncbiexpt.hpp:887
@ eInvalidCharacter
Parameter value contains invalid character.
Definition: ncbiexpt.hpp:1509
@ eUndefined
Parameter is missing/undefined.
Definition: ncbiexpt.hpp:1508
@ eUnknown
Definition: app_popup.hpp:72
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
bool IsOssEmpty(CNcbiOstrstream &oss)
Definition: ncbistre.hpp:831
#define kEmptyStr
Definition: ncbistr.hpp:123
char TXChar
Definition: ncbistr.hpp:172
#define _T_STDSTRING(x)
Definition: ncbistr.hpp:180
#define _T_XCSTRING(x)
Definition: ncbistr.hpp:181
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3883
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
Definition: ncbistr.cpp:68
void SetValue(TValue *value, FCleanup cleanup=0, void *cleanup_data=0, CTlsBase::ENativeThreadCleanup native=CTlsBase::eSkipCleanup)
Definition: ncbithr.hpp:338
#define ErrCode()
Get the error code for the last failed system function.
Definition: mdb.c:377
Definition of all error codes used in corelib (xncbi.lib).
FILE * file
static void text(MDB_val *v)
Definition: mdb_dump.c:62
static MDB_envinfo info
Definition: mdb_load.c:37
Static variables safety - create on demand, destroy on application termination.
NCBI_PARAM_ENUM_DECL(EDiagSev, EXCEPTION, Stack_Trace_Level)
static atomic< bool > s_DoThrowTraceAbort(false)
NCBI_PARAM_DEF_EX(bool, EXCEPTION, Abort_If_Critical, false, eParam_NoThread, EXCEPTION_ABORT_IF_CRITICAL)
static void s_TlsErrorMessageCleanup(char *msg, void *)
Definition: ncbiexpt.cpp:820
NCBI_PARAM_ENUM_ARRAY(EDiagSev, EXCEPTION, Stack_Trace_Level)
Definition: ncbiexpt.cpp:109
NCBI_PARAM_ENUM_DEF_EX(EDiagSev, EXCEPTION, Stack_Trace_Level, eDiag_Critical, eParam_NoThread, EXCEPTION_STACK_TRACE_LEVEL)
NCBI_PARAM_DECL(bool, EXCEPTION, Abort_If_Critical)
static atomic< bool > s_DTTA_Initialized(false)
static CSafeStatic< TAbortIfCritical > s_AbortIfCritical
Definition: ncbiexpt.cpp:150
static CStaticTls< char > s_TlsErrorMessage
Definition: ncbiexpt.cpp:819
typedef NCBI_PARAM_TYPE(EXCEPTION, Stack_Trace_Level) TStackTraceLevelParam
Defines NCBI C++ exception handling.
Multi-threading – classes, functions, and features.
void abort()
Defines CRequestContext class for NCBI C++ diagnostic API.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define NcbiSys_strerror
Definition: ncbisys.hpp:105
#define NcbiSys_getenv
Definition: ncbisys.hpp:90
#define NcbiSys_strerror_s
Definition: ncbisys.hpp:106
SDiagMessage –.
Definition: ncbidiag.hpp:1599
Modified on Fri Sep 20 14:58:14 2024 by modify_doxy.py rev. 669887