54 #define NCBI_USE_ERRCODE_X Corelib_Diag
99 const char* msg1,
const char* msg2)
126 EXCEPTION_STACK_TRACE_LEVEL);
131 TStackTraceLevelParam::SetDefault(level);
137 return TStackTraceLevelParam::GetDefault();
147 EXCEPTION_ABORT_IF_CRITICAL);
172 const string& message,
175 : m_Severity(severity),
187 x_Init(
info, message, prev_exception, severity);
194 const string& message,
197 : m_Severity(severity),
209 x_Init(
info, message, prev_exception, severity);
217 const string& message)
218 : m_Severity(args.GetSeverity()),
219 m_ErrCode(args.GetErrCode()),
223 m_Flags(args.GetFlags()),
262 delete m_Predecessor;
275 const string& message,
290 if (add_msg.empty()) {
344 m_What = ReportAll();
345 if ( m_StackTrace.get() && !m_StackTrace->Empty() ) {
347 string old_prefix = m_StackTrace->GetPrefix();
348 m_StackTrace->SetPrefix(
" ");
349 os <<
" Stack trace:\n" << *m_StackTrace;
350 m_StackTrace->SetPrefix(old_prefix);
353 return m_What.c_str();
373 stack<const CException*> pile;
379 os <<
"NCBI C++ Exception:" <<
'\n';
380 for (; !pile.empty(); pile.pop()) {
383 os << pile.top()->ReportThis(
flags) <<
'\n';
389 "(background reporting)",
448 default:
return "eInvalid";
463 for (
const CException* ex =
this; ex !=
NULL; ex = ex->m_Predecessor) {
464 if ( !ex->m_Msg.empty() ) {
480 #if defined(NCBI_OS_MSWIN) && defined(_DEBUG)
483 os <<
"NCBI C++ Exception:" <<
'\n';
562 m_ErrCode =
typeid(*this) ==
typeid(src) ?
589 const char* human_name)
const
591 const type_info& actual_type =
typeid(*this);
595 <<
" [" << human_name <<
']');
644 const exception& ex);
647 virtual const char*
GetType(
void)
const;
684 unique_ptr<CException> wrapper;
698 d <<
ErrCode(err_code, err_subcode) << title <<
" " << *cex;
736 m_Out <<
"NCBI C++ Exception:" << endl;
738 stack<const CException*> pile;
743 for (; !pile.empty(); pile.pop()) {
760 case eCore:
return "eCore";
762 case eDll:
return "eDll";
781 #if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
782 (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
785 static void s_TlsStrerrorMessageCleanup(
char*
msg,
void* )
795 #if (defined(NCBI_OS_MSWIN) && defined(_UNICODE)) || \
796 (NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__)
798 # if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400) && __STDC_WANT_SECURE_LIB__
805 char* ptr =
new char[
tmp.size() + 1];
806 strcpy(ptr,
tmp.c_str());
807 s_TlsStrerrorMessage.
SetValue(ptr, s_TlsStrerrorMessageCleanup);
816 #if defined(NCBI_OS_MSWIN)
829 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
830 FORMAT_MESSAGE_FROM_SYSTEM |
831 FORMAT_MESSAGE_MAX_WIDTH_MASK |
832 FORMAT_MESSAGE_IGNORE_INSERTS,
834 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
836 #if defined(_UNICODE)
838 char* ptr = (
char*) LocalAlloc(LPTR,
tmp.size() + 1);
839 strcpy(ptr,
tmp.c_str());
845 size_t pos = strlen(ptr);
847 while (--pos && (ptr[pos] ==
'.' || ptr[pos] ==
' ')) {
864 "Attempt to access NULL CNullable value.");
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
virtual const char * GetType(void) const
virtual const char * GetErrCodeString(void) const
CExceptionWrapper(const CDiagCompileInfo &info, const exception &ex)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CRequestContext & GetRequestContext(void)
CRequestContextRef(CRequestContext &ctx)
CRef< CRequestContext > m_Context
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * str(char *buf, int n)
static char expected_type[20]
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
void Write(string &str, TDiagWriteFlags flags=fNone) const
Binary OR of "EDiagWriteFlags".
CDiagContext & GetDiagContext(void)
Get diag context instance.
int TDiagPostFlags
Binary OR of "EDiagPostFlag".
#define NCBI_CURRENT_FUNCTION
Get current function name.
int CompareDiagPostLevel(EDiagSev sev1, EDiagSev sev2)
Compare two severities.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void SetOmitStackTrace(bool value)
EDiagSev
Severity level for the posted diagnostics.
@ eDPF_Exception
Default flags to use for exception formatting.
@ fNoPrefix
No std prefix.
@ eDiag_Trace
Trace message.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
@ eDiag_Critical
Critical error message.
bool m_MainText
Exception has main text.
virtual ~CExceptionReporterStream(void)
Destructor.
string m_File
File to report on.
const string & GetModule(void) const
Get module name used for reporting.
const char * Ncbi_strerror(int errnum)
void AddPrevious(const CException *prev_exception)
virtual void ReportExtra(ostream &out) const
Report "non-standard" attributes.
static void SetDefault(const CExceptionReporter *handler)
Set default reporter.
void x_GetStackTrace(void)
Get and store current stack trace.
virtual const char * GetType(void) const
Get class name as a string.
void Report(const CDiagCompileInfo &info, const string &title, CExceptionReporter *reporter=0, TDiagPostFlags flags=eDPF_Exception) const
Report the exception.
static const char * GetErrCodeString(int errnum)
bool IsSetModule(void) const
ERetriable GetRetriable(void) const
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...
static const CExceptionReporter * sm_DefHandler
Default handler.
virtual void Throw(void) const
Polymorphically (re)throw an exception whose exact type is uncertain.
TFlags m_Flags
Flags, hints, attributes.
TExceptionPtr m_Predecessor
Previous exception.
const string & GetFile(void) const
Get file name used for reporting.
void DoThrowTraceAbort(void)
"abort()" the program if set by SetThrowTraceAbort() or $ABORT_ON_THROW.
TErrCode GetErrCode(void) const
Get error code.
static void ReportDefault(const CDiagCompileInfo &info, const string &title, const std::exception &ex, TDiagPostFlags flags=eDPF_Exception)
Report exception using default reporter.
virtual int x_GetErrCode(void) const
Helper method for getting error code.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
virtual ~CException(void) noexcept
Destructor.
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.
ERetriable m_Retriable
In some cases it is known for sure if an action caused the exception can be tried again or not.
ostream & m_Out
Output stream.
CExceptionReporter(void)
Constructor.
static bool sm_DefEnabled
Default enable flag.
const string & GetMsg(void) const
Get message string.
static bool EnableDefault(bool enable)
Enable/disable using default reporter.
static const CExceptionReporter * GetDefault(void)
Get default reporter.
CRequestContext & GetRequestContext(void) const
Get the request context in which the exception was thrown.
void Warning(CExceptionArgs_Base &args)
virtual void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity)
Helper method for initializing exception data.
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
string m_Function
Function to report on.
virtual void x_InitErrCode(CException::EErrCode err_code)
Helper method for initializing error code.
virtual void x_Assign(const CException &src)
Helper method for copying exception data.
void ReportStd(ostream &out, TDiagPostFlags flags=eDPF_Exception) const
Report "standard" attributes.
CExceptionReporterStream(ostream &out)
Constructor.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
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.
void AddToMessage(const string &add_msg)
EDiagSev m_Severity
Severity level for the exception.
string m_Module
Module to report on.
const string & GetClass(void) const
Get class name used for reporting.
virtual const CException * x_Clone(void) const
Helper method for cloning the exception.
#define ABORT_ON_THROW
ABORT_ON_THROW controls if program should be aborted.
unique_ptr< CStackTrace > m_StackTrace
Saved stack trace.
static EDiagSev GetStackTraceLevel(void)
Get current severity level for saving and printing stack trace.
EErrCode
Error types that an application can generate.
TErrCode GetErrCode(void) const
string ReportThis(TDiagPostFlags flags=eDPF_Exception) const
Report this exception only.
const string & GetModule(void) const
virtual const char * GetErrCodeString(void) const override
Translate from an error code value to its string representation.
virtual void x_AssignErrCode(const CException &src)
Helper method for assigning error code.
const string & GetFunction(void) const
Get function name used for reporting.
unique_ptr< CRequestContextRef > m_RequestContext
void DoDbgPrint(const CDiagCompileInfo &info, const char *message)
Print the specified debug message.
EDiagSev GetSeverity(void) const
Get exception severity.
CException & SetSeverity(EDiagSev severity)
Set exception severity.
virtual ~CExceptionReporter(void)
Destructor.
void x_ThrowSanityCheck(const type_info &expected_type, const char *human_name) const
Warn if Throw() will end up slicing its invocant.
virtual void x_ReportToDebugger(void) const
Helper method for reporting to the system debugger.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
static bool sm_BkgrEnabled
Background reporting enabled flag.
string m_Class
Class to report on.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
void AddBacklog(const CDiagCompileInfo &info, const string &message, EDiagSev severity=eDiag_Error)
Add a message to backlog (to re-throw the same exception then).
int GetLine(void) const
Get line number where error occurred.
bool m_InReporter
Reporter flag.
virtual void x_InitArgs(const CExceptionArgs_Base &args)
Process additional arguments.
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
static void SetStackTraceLevel(EDiagSev level)
Set severity level for saving and printing stack trace.
void SetThrowTraceAbort(bool abort_on_throw_trace)
Specify whether to call "abort()" inside the DoThrowTraceAbort().
string m_Msg
Message string.
const CException * GetPredecessor(void) const
Get "previous" exception from the backlog.
CException(void)
Constructor with no arguments.
const CStackTrace * GetStackTrace(void) const
Get the saved stack trace if available or NULL.
TErrCode GetErrCode(void) const
@ eCore
Generic corelib error.
@ eDiagFilter
Illegal syntax of the diagnostics filter string.
@ eNullPtr
Null pointer error.
@ eInvalidArg
Invalid argument error.
@ eInvalid
To be used ONLY as a return value; please, NEVER throw an exception with this code.
@ eUnknown
Unknown exception.
@ eInvalidCharacter
Parameter value contains invalid character.
@ eUndefined
Parameter is missing/undefined.
@ eParam_NoThread
Do not use per-thread values.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
bool IsOssEmpty(CNcbiOstrstream &oss)
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
void SetValue(TValue *value, FCleanup cleanup=0, void *cleanup_data=0, CTlsBase::ENativeThreadCleanup native=CTlsBase::eSkipCleanup)
#define ErrCode()
Get the error code for the last failed system function.
Definition of all error codes used in corelib (xncbi.lib).
static void text(MDB_val *v)
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 *)
NCBI_PARAM_ENUM_ARRAY(EDiagSev, EXCEPTION, Stack_Trace_Level)
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
static CStaticTls< char > s_TlsErrorMessage
typedef NCBI_PARAM_TYPE(EXCEPTION, Stack_Trace_Level) TStackTraceLevelParam
Defines NCBI C++ exception handling.
Multi-threading – classes, functions, and features.
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_s