📄 exception.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: exception.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:19:05 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//* $Id: exception.cpp,v 1000.2 2004/06/01 19:19:05 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Denis Vakatov, Vladimir Soussov * * File Description: Exceptions * */#include <ncbi_pch.hpp>#include <dbapi/driver/exception.hpp>BEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////// CDB_Exception:://CDB_Exception::CDB_Exception(EType type, EDB_Severity severity, int err_code, const string& originated_from, const string& msg){ m_Type = type; m_Severity = severity; m_ErrCode = err_code; m_OriginatedFrom = originated_from; m_Message = msg;}CDB_Exception::~CDB_Exception() throw(){ return;}const char* CDB_Exception::what() const throw(){ if ( m_What.empty() ) { try { x_ComposeWhat(); } catch (exception& ex) { static char s_StartOfWhat[] = "CDB_Exception::what(): x_ComposeWhat() threw an exception: "; static char s_What[sizeof(s_StartOfWhat) + 128]; strcpy(s_What, s_StartOfWhat); const char* ex_what = ex.what() ? ex.what() : "NULL"; size_t len = strlen(s_StartOfWhat); strncpy(s_What + len, ex_what, sizeof(s_What) - strlen(s_StartOfWhat) - 1); s_What[sizeof(s_What) - 1] = '\0'; return s_What; } } return m_What.c_str();}const char* CDB_Exception::SeverityString(EDB_Severity sev){ switch ( sev ) { case eDB_Info: return "Info"; case eDB_Warning: return "Warning"; case eDB_Error: return "Error"; case eDB_Fatal: return "Fatal"; default: return "Unclear"; }}void CDB_Exception::x_ComposeWhat(void) const{ x_StartOfWhat(&m_What); x_EndOfWhat(&m_What);}string& CDB_Exception::x_StartOfWhat(string* str) const{ *str += "["; *str += SeverityString(); *str += " #"; *str += NStr::IntToString(ErrCode()); *str += ", "; *str += TypeString(); *str += " in "; *str += OriginatedFrom(); *str += "] "; return *str;}string& CDB_Exception::x_EndOfWhat(string* str) const{ *str += "<<<"; *str += Message(); *str += ">>>"; return *str;}/////////////////////////////////////////////////////////////////////////////// CDB_DSEx:://const char* CDB_DSEx::TypeString() const{ return "Data_Source";}CDB_Exception* CDB_DSEx::Clone() const{ return new CDB_DSEx (m_Severity, m_ErrCode, m_OriginatedFrom, m_Message);}/////////////////////////////////////////////////////////////////////////////// CDB_RPCEx:://CDB_RPCEx::CDB_RPCEx(EDB_Severity severity, int err_code, const string& originated_from, const string& msg, const string& proc_name, int proc_line) : CDB_Exception(eRPC, severity, err_code, originated_from, msg){ static const string s_UnknownProcName = "Unknown"; m_ProcName = proc_name.empty() ? s_UnknownProcName : proc_name; m_ProcLine = proc_line;}CDB_RPCEx::~CDB_RPCEx() throw(){ return;}const char* CDB_RPCEx::TypeString() const{ return "Remote_Procedure_Call";}CDB_Exception* CDB_RPCEx::Clone() const{ return new CDB_RPCEx (m_Severity, m_ErrCode, m_OriginatedFrom, m_Message, m_ProcName, m_ProcLine);}void CDB_RPCEx::x_ComposeWhat(void) const{ x_StartOfWhat(&m_What); m_What += "Procedure '"; m_What += ProcName(); m_What += "', Line "; m_What += NStr::IntToString(ProcLine()); x_EndOfWhat(&m_What);}/////////////////////////////////////////////////////////////////////////////// CDB_SQLEx:://CDB_SQLEx::CDB_SQLEx(EDB_Severity severity, int err_code, const string& originated_from, const string& msg, const string& sql_state, int batch_line) : CDB_Exception(eSQL, severity, err_code, originated_from, msg){ static const string s_UnknownSqlState = "Unknown"; m_SqlState = sql_state.empty() ? s_UnknownSqlState : sql_state; m_BatchLine = batch_line;}CDB_SQLEx::~CDB_SQLEx() throw(){ return;}const char* CDB_SQLEx::TypeString() const{ return "SQL";}CDB_Exception* CDB_SQLEx::Clone() const{ return new CDB_SQLEx (m_Severity, m_ErrCode, m_OriginatedFrom, m_Message, m_SqlState, m_BatchLine);}void CDB_SQLEx::x_ComposeWhat(void) const{ x_StartOfWhat(&m_What); m_What += "Procedure '"; m_What += SqlState(); m_What += "', Line "; m_What += NStr::IntToString(BatchLine()); x_EndOfWhat(&m_What);}/////////////////////////////////////////////////////////////////////////////// CDB_DeadlockEx:://const char* CDB_DeadlockEx::TypeString() const{ return "Deadlock";}CDB_Exception* CDB_DeadlockEx::Clone() const{ return new CDB_DeadlockEx (m_OriginatedFrom, m_Message);}/////////////////////////////////////////////////////////////////////////////// CDB_TimeoutEx:://const char* CDB_TimeoutEx::TypeString() const{ return "Timeout";}CDB_Exception* CDB_TimeoutEx::Clone() const{ return new CDB_TimeoutEx (m_ErrCode, m_OriginatedFrom, m_Message);}/////////////////////////////////////////////////////////////////////////////// CDB_ClientEx:://const char* CDB_ClientEx::TypeString() const{ return "Client";}CDB_Exception* CDB_ClientEx::Clone() const{ return new CDB_ClientEx (m_Severity, m_ErrCode, m_OriginatedFrom, m_Message);}/////////////////////////////////////////////////////////////////////////////// CDB_MultiEx:://CDB_MultiEx::CDB_MultiEx(const string& originated_from, unsigned int capacity) : CDB_Exception(eMulti, eDB_Unknown, 0, originated_from, kEmptyStr){ m_Bag = new CDB_MultiExStorage(capacity);}CDB_MultiEx::CDB_MultiEx(const CDB_MultiEx& mex) : CDB_Exception(eMulti, eDB_Unknown, 0, mex.m_OriginatedFrom, mex.m_Message){ m_Bag = mex.m_Bag; m_Bag->AddRef();}CDB_MultiEx::~CDB_MultiEx() throw(){ m_Bag->DelRef();}const char* CDB_MultiEx::TypeString() const{ return "MultiException";}CDB_Exception* CDB_MultiEx::Clone() const{ return new CDB_MultiEx(*this);}string CDB_MultiEx::WhatThis(void) const{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -