ui-utilcpp 1.10.4
UI::Exception Class Reference

Generic exception class for namespace UI. More...

#include <Exception.hpp>

Inheritance diagram for UI::Exception:
Inheritance graph
Collaboration diagram for UI::Exception:
Collaboration graph

Public Member Functions

 Exception (std::string const &what=NoWhatGiven_, std::string const &debug=NoDebugGiven_, int const &errNo=0)
 Construct with description text.
 
Get exception information.
char const * what () const throw ()
 
int const & getErrno () const
 
std::string getDebug () const
 

Static Public Attributes

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 Protected Attributes

These constants may be used for description default values for derived classes.
static std::string const NoWhatGiven_
 
static std::string const NoDebugGiven_
 

Detailed Description

Generic exception class for namespace UI.

Exception HOWTO

User's guide (exception handlers)

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.

Constructor & Destructor Documentation

◆ 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
whatException description. Errno_ text in string will be replaced with error string.
debugAny debug text.
errNoDedicated "errno" error number.

The documentation for this class was generated from the following files: