⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbiexpt.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 3 页
字号:
catch (NCBI_NS_STD::exception& e) { \      NCBI_NS_NCBI::CNcbiDiag() << NCBI_NS_NCBI::Error \           << "[" << message << "]" << "Exception: " << e.what(); \}/// Standard handling of "exception"-derived exceptions; catches non-standard/// exceptiuons and generates "unknown exception" for all other exceptions.#define STD_CATCH_ALL(message) \STD_CATCH(message) \    catch (...) { \      NCBI_NS_NCBI::CNcbiDiag() << NCBI_NS_NCBI::Error \           << "[" << message << "]" << "Unknown exception"; \}/////////////////////////////////////////////////////////////////////////////// CException: useful macros/// Generic macro to throw an exception, given the exception class,/// error code and message string.#define NCBI_THROW(exception_class, err_code, message) \    throw exception_class(__FILE__, __LINE__, \        0,exception_class::err_code, (message))/// Generic macro to re-throw an exception.#define NCBI_RETHROW(prev_exception, exception_class, err_code, message) \    throw exception_class(__FILE__, __LINE__, \        &(prev_exception), exception_class::err_code, (message))/// Generic macro to re-throw the same exception.#define NCBI_RETHROW_SAME(prev_exception, message) \    do { prev_exception.AddBacklog(__FILE__, __LINE__, message); \    throw; }  while (0)/// Generate a report on the exception.#define NCBI_REPORT_EXCEPTION(title,ex) \    CExceptionReporter::ReportDefault(__FILE__,__LINE__,title,ex,eDPF_Default)/////////////////////////////////////////////////////////////////////////////// CException// Forward declaration of CExceptionReporter.class CExceptionReporter;/////////////////////////////////////////////////////////////////////////////////// CException --////// Define an extended exception class based on the C+++ std::exception.////// CException inherits its basic functionality from std::exception and/// defines additional generic error codes for applications, and error/// reporting capabilities.class NCBI_XNCBI_EXPORT CException : public std::exception{public:    /// Error types that an application can generate.    ///    /// Each derived class has its own error codes and their interpretations.    /// Define two generic error codes "eInvalid" and "eUnknown" to be used    /// by all NCBI applications.    enum EErrCode {        eInvalid = -1, ///< To be used ONLY as a return value;                       ///< please, NEVER throw an exception with this code.        eUnknown = 0   ///< Unknown exception.    };    typedef int TErrCode;    /// Constructor.    ///    /// When throwing an exception initially, "prev_exception" must be 0.    CException(const char* file, int line,               const CException* prev_exception,               EErrCode err_code,const string& message) throw();    /// Copy constructor.    CException(const CException& other) throw();    /// Add a message to backlog (to re-throw the same exception then).    void AddBacklog(const char* file, int line,const string& message);    // ---- Reporting --------------    /// Standard report (includes full backlog).    virtual const char* what(void) const throw();    /// Report the exception.    ///    /// Report the exception using "reporter" exception reporter.    /// If "reporter" is not specified (value 0), then use the default    /// reporter as set with CExceptionReporter::SetDefault.    void Report(const char* file, int line,                const string& title, CExceptionReporter* reporter = 0,                TDiagPostFlags flags = eDPF_Trace) const;    /// Report this exception only.    ///    /// Report as a string this exception only. No backlog is attached.    string ReportThis(TDiagPostFlags flags = eDPF_Trace) const;    /// Report all exceptions.    ///    /// Report as a string all exceptions. Include full backlog.    string ReportAll (TDiagPostFlags flags = eDPF_Trace) const;    /// Report "standard" attributes.    ///    /// Report "standard" attributes (file, line, type, err.code, user message)    /// into the "out" stream (this exception only, no backlog).    void ReportStd(ostream& out, TDiagPostFlags flags = eDPF_Trace) const;    /// Report "non-standard" attributes.    ///    /// Report "non-standard" attributes (those of derived class) into the    /// "out" stream.    virtual void ReportExtra(ostream& out) const;    /// Enable background reporting.    ///    /// If background reporting is enabled, then calling what() or ReportAll()    /// would also report exception to the default exception reporter.    /// @return    ///   The previous state of the flag.    static bool EnableBackgroundReporting(bool enable);    // ---- Attributes ---------    /// Get class name as a string.    virtual const char* GetType(void) const;    /// Get error code interpreted as text.    virtual const char* GetErrCodeString(void) const;    /// Get file name used for reporting.    const string& GetFile(void) const { return m_File; }    /// Get line number where error occurred.    int GetLine(void) const { return m_Line; }    /// Get error code.    TErrCode GetErrCode(void) const;    /// Get message string.    const string& GetMsg (void) const { return m_Msg;  }    /// Get "previous" exception from the backlog.    const CException* GetPredecessor(void) const { return m_Predecessor; }    /// Destructor.    virtual ~CException(void) throw();protected:    /// Constructor with no arguments.    ///    /// Required in case of multiple inheritance.    CException(void) throw();    /// Helper method for reporting to the system debugger.    virtual void x_ReportToDebugger(void) const;    /// Helper method for cloning the exception.    virtual const CException* x_Clone(void) const;    /// Helper method for initializing exception data.    virtual void x_Init(const string& file, int line,                        const string& message,                        const CException* prev_exception);    /// Helper method for copying exception data.    virtual void x_Assign(const CException& src);        /// Helper method for assigning error code.    virtual void x_AssignErrCode(const CException& src);    /// Helper method for initializing error code.    virtual void x_InitErrCode(CException::EErrCode err_code);    /// Helper method for getting error code.    virtual int  x_GetErrCode(void) const { return m_ErrCode; }private:    string  m_File;                  ///< File to report on    int     m_Line;                  ///< Line number    int     m_ErrCode;               ///< Error code    string  m_Msg;                   ///< Message string    mutable string m_What;           ///< What type of exception    const CException* m_Predecessor; ///< Previous exception    mutable bool m_InReporter;       ///< Reporter flag    static  bool sm_BkgrEnabled;     ///< Background reporting enabled flag    /// Private assignment operator to prohibit assignment.    CException& operator= (const CException&) throw();};/// Return valid pointer to uppermost derived class only if "from" is _really_ /// the object of the desired type.////// Do not cast to intermediate types (return NULL if such cast is attempted).template <class TTo, class TFrom>const TTo* UppermostCast(const TFrom& from){    return typeid(from) == typeid(TTo) ? dynamic_cast<const TTo*>(&from) : 0;}/// Helper macro for default exception implementation./// @sa///   NCBI_EXCEPTION_DEFAULT#define NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION(exception_class, base_class) \    { \        x_Init(file,line,message, prev_exception); \        x_InitErrCode((CException::EErrCode) err_code); \    } \    exception_class(const exception_class& other) throw() \       : base_class(other) \    { \        x_Assign(other); \    } \    virtual ~exception_class(void) throw() {} \    virtual const char* GetType(void) const {return #exception_class;} \    typedef int TErrCode; \    TErrCode GetErrCode(void) const \    { \        return typeid(*this) == typeid(exception_class) ? \            (TErrCode)x_GetErrCode() : (TErrCode)CException::eInvalid; \    } \protected: \    exception_class(void) throw() {} \    virtual const CException* x_Clone(void) const \    { \        return new exception_class(*this); \    } \private: \    /* for the sake of semicolon at the end of macro...*/ \    static void xx_unused_##exception_class(void)/// To help declare new exception class.////// This can be used ONLY if the derived class does not have any additional/// (non-standard) data members.#define NCBI_EXCEPTION_DEFAULT(exception_class, base_class) \public: \    exception_class(const char* file,int line, \        const CException* prev_exception, \        EErrCode err_code,const string& message) throw() \        : base_class(file, line, prev_exception, \            (base_class::EErrCode) CException::eInvalid, (message)) \    NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION(exception_class, base_class)/// Helper macro added to support templatized exceptions.////// GCC starting from 3.2.2 warns about implicit typenames - this macro fixes/// the warning.#define NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION_TEMPL(exception_class, base_class) \    { \        this->x_Init(file,line,message, prev_exception); \        this->x_InitErrCode((typename CException::EErrCode) err_code); \    } \    exception_class(const exception_class& other) throw() \       : base_class(other) \    { \        x_Assign(other); \    } \    virtual ~exception_class(void) throw() {} \    virtual const char* GetType(void) const {return #exception_class;} \    typedef int TErrCode; \    TErrCode GetErrCode(void) const \    { \        return typeid(*this) == typeid(exception_class) ? \            (TErrCode) this->x_GetErrCode() : \            (TErrCode) CException::eInvalid; \    } \protected: \    exception_class(void) throw() {} \    virtual const CException* x_Clone(void) const \    { \        return new exception_class(*this); \    } \private: \    /* for the sake of semicolon at the end of macro...*/ \   // static void xx_unused_##exception_class(void)/// Exception bug workaround for GCC version less than 3.00.////// GCC compiler v.2.95 has a bug: one should not use virtual base class in/// exception declarations - a program crashes when deleting such an exception/// (this is fixed in newer versions of the compiler).#if defined(NCBI_COMPILER_GCC)#  if NCBI_COMPILER_VERSION < 300#    define EXCEPTION_BUG_WORKAROUND#  endif#endif#if defined(EXCEPTION_BUG_WORKAROUND)#  define EXCEPTION_VIRTUAL_BASE#else#  define EXCEPTION_VIRTUAL_BASE virtual#endif/////////////////////////////////////////////////////////////////////////////////// CExceptionReporter --////// Define exception reporter.class NCBI_XNCBI_EXPORT CExceptionReporter{public:    /// Constructor.    CExceptionReporter(void);    /// Destructor.    virtual ~CExceptionReporter(void);    /// Set default reporter.    static void SetDefault(const CExceptionReporter* handler);    /// Get default reporter.    static const CExceptionReporter* GetDefault(void);    /// Enable/disable using default reporter.    ///    /// @return    ///   Previous state of this flag.    static bool EnableDefault(bool enable);    /// Report exception using default reporter.    static void ReportDefault(const char* file, int line,                              const string& title, const CException& ex,                              TDiagPostFlags flags = eDPF_Trace);    /// Report exception with _this_ reporter    virtual void Report(const char* file, int line,                        const string& title, const CException& ex,                        TDiagPostFlags flags = eDPF_Trace) const = 0;private:    static const CExceptionReporter* sm_DefHandler; ///< Default handler    static bool                      sm_DefEnabled; ///< Default enable flag};/////////////////////////////////////////////////////////////////////////////////// CExceptionReporterStream --////// Define exception reporter stream.class NCBI_XNCBI_EXPORT CExceptionReporterStream : public CExceptionReporter{public:    /// Constructor.    CExceptionReporterStream(ostream& out);    /// Destructor.    virtual ~CExceptionReporterStream(void);    /// Report specified exception on output stream.    virtual void Report(const char* file, int line,                        const string& title, const CException& ex,                        TDiagPostFlags flags = eDPF_Trace) const;private:    ostream& m_Out;   ///< Output stream};/////////////////////////////////////////////////////////////////////////////////// CCoreException --////// Define corelib exception.  CCoreException inherits its basic/// functionality from CException and defines additional error codes for/// applications.class NCBI_XNCBI_EXPORT CCoreException : EXCEPTION_VIRTUAL_BASE public CException{public:    /// Error types that  corelib can generate.    ///    /// These generic error conditions can occur for corelib applications.     enum EErrCode {        eCore,          ///< Generic corelib error        eNullPtr,       ///< Null pointer error        eDll,           ///< Dll error        eInvalidArg     ///< Invalid argument error

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -