?? exception.h
字號(hào):
/*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************//** * Copyright (c) 2000 * * A C++ implementation of Asynchronous Input/Output, using threaded * objects to handle the data. * */#ifndef THREAD_EXCEPTION#define THREAD_EXCEPTION#include <string>#include <exception>extern "C" {#include <setjmp.h>};namespace cpp_threads { /** * Exception * * A common class, that holds all kinds of errors that can be * cought by an exception handler. The handler, can than * act on the error reported. * * Some compilers, do not make the actual data in the class * until after the constructor has finished. This does * constitute a problem in some cases, which introduces for * us more types of exceptions. A fatal exception, will be * thrown right away, inside the constructor, while other * kinds must be thrown by the user. * * @short Abstract class for exceptions. * @author Orn E. Hansen <oe.hansen@gamma.telenordia.se> */ class exception : public std::exception { public: /** * These are the kinds of exceptions, that are defined. In * C++ there is only one possible exception, a fatal one, * as it is not possible to return from the exception handler, * but this just *may* be possible in future version, and is * the intention of these exception types. */ enum tType { /** Undefined exception... same as none. */ ex_none, /** A fatal exception, that will always result in a throw. */ ex_fatal, /** Reserved for future expansion, non fatal warning. */ ex_warning, /** Reserved for future expansion, non fatal interception requested. */ ex_intercept }; private: std::string mTextMessage; void *mBuffer; tType mErrorKind; int mErrno; bool mState; sigjmp_buf mEnv; public: /** * The typical construction of an exception, will merely * hold a textual message, and throw an error. The * constructor takes two parameters, one being the message * and the other the type of exception. The type, as * give in the enumeration above, will determine wether the * exception creation will terminate immediately or * wait until the programmer determines it should. * * @param s String message * @param t Type of exception */ exception(const std::string&,tType t=ex_fatal); virtual ~exception() throw(); /** * Each exception may hold a numerical error, in accordance * with C errno variable. This is to set this error number * to a specific value. Setting the errno to 0, in an exception * handler that has already been thrown, and is not a fatal * exception, will return to the point where it was thrown. Thus * giving the user the ability to correct an error. * * @param n The error number value. */ void setError(int); /** * Return the value of the error variable, as set during the * exceptioon process. * * @return The error value. */ int error(); /** * Set the message, this exception will contain. Usually a * textual representation of the error. * * @param t String containing the error message */ void setMessage(const std::string&); /** * Obtain the error message, this is the std::exception * method for this. * * @return Error message. */ const char *what(); /** * Obtain the error message, set during the exception * process. * * @return Error message. */ std::string message() const; /** * Set the exception type, if different from the * created one. How useful this is, not very... but when * exceptions become recoverable, on class may be reusable * for error processing/recovering. * * @param t The exception type. */ virtual void setException(tType); /** * Obtain the severity of the exception, as stated during the * exception processing. * * @return Error severity, exception type. */ tType severity(); /** * A static member, that creates a textual exception with some * specific type. The exception will be throw immediately upon * creation. * * @param s String message for the error. * @param t The type of exception to create. */ static void staticException(const std::string&,tType); /** * This static member, creates an error with an integer value * that is assumed to be in accordance with the C errno variable, * and the textual message of this error is loaded as the * text message, before throwing the exception. * * @param n Error value, according to errno values. * @param t The exception type to create. */ static void staticException(int,tType); static void fatal(int e) { staticException(e,ex_fatal); }; static void fatal(const std::string& p) { staticException(p,ex_fatal); }; static void warning(int e) { staticException(e,ex_warning); }; static void warning(const std::string& p) { staticException(p,ex_warning); }; static void intercept(int e) { staticException(e,ex_intercept); }; static void intercept(const std::string& p) { staticException(p,ex_intercept); }; };};#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -