Generic exception class for namespace UI.
More...
#include <Exception.hpp>
|
| Exception (std::string const &what=NoWhatGiven_, std::string const &debug=NoDebugGiven_, int const &errNo=0) |
| Construct with description text.
|
|
|
char const * | what () const throw () |
|
int const & | getErrno () const |
|
std::string | getDebug () const |
|
|
static std::string const | Errno_ |
| If this string is used in a "what" description message, it will be replaced by an errno error string.
|
|
|
|
static std::string const | NoWhatGiven_ |
|
static std::string const | NoDebugGiven_ |
|
Generic exception class for namespace UI.
Exception HOWTO
User's guide (exception handlers)
- For standard (no "code" support), just use intuitively. For example, UI::Exception catches any S+P Exception, UI::Util::Exception any S+P exception in namespace UI::Util, UI::Util::File::Exception any exception of class UI::Util::File.
- Any time you want to catch code exceptions, you will always need a dedicated handler (knowing the code semantics) anyway. For example, knowing UI::Util::File::Exception is a code exception, catch exactly that exception and evaluate further using getCode().
Developer's guide (write own exception classes)
Preliminaries
- In any context (namespace or class), a class "Exception" should be available, using UI::Exception or UI::CodeException constructor syntax; this is needed so UI_THROW* macros can be used.
- Note that the "interfacing" exception class is always called "Exception", even if it is a code exception. The CodeException template is only used to ease writing classes w/ dedicated code number support.
- Be sure that your exception class always inherits the next class "context up". For example UI::Util::Sys::Exception must inherit from UI::Util::Exception, not UI::Exception; else a handler on UI::Util::Exception would not catch UI::Util::Sys::Exception, which is against intuitive use of exceptions. The same holds true for mere typedefs.
Quickstart
Let's say, you invented a new namespace "UI::Humbug".
- In the simplest case, if you don't need support to catch down all UI::Humbug's exceptions, you may just use UI_THROW*-macros w/o any additional code.
- Alternatively, if UI::Humbug needs a generic exception class so we can catch it all down, just use the very same source code for UI::Util::Exception in your new namespace.
- Optionally, if you want to ease the use of code exceptions in your namespace for sub-contexts, just use the very code for the UI::Util::CodeException template in your namespace.
- Alernatively, if your new namespace's generic exception class is to be a code exception itself, inherit UI::Humbug::Exception from UI::CodeException<HumbugCode>.
The above three points typically go into "Exception.hpp" of your project.
- Optionally, you can now add exception classes for sub-contexts (sub-namespaces or classes) if needed.
- To throw exceptions, always use macros UI_THROW, UI_THROW_CODE, UI_THROW_ERRNO or UI_THROW_CODE_ERRNO.
- Examples
- EchoServer.cpp.
◆ Exception()
UI::Exception::Exception |
( |
std::string const & |
what = NoWhatGiven_ , |
|
|
std::string const & |
debug = NoDebugGiven_ , |
|
|
int const & |
errNo = 0 |
|
) |
| |
Construct with description text.
- Note
- You usually do not call this constructor directly, but instead always use one of the UI_THROW_* macros above.
- Parameters
-
what | Exception description. Errno_ text in string will be replaced with error string. |
debug | Any debug text. |
errNo | Dedicated "errno" error number. |
The documentation for this class was generated from the following files: