E-MailRelay
|
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer. More...
#include <gexceptionsink.h>
Public Member Functions | |
ExceptionSink () noexcept | |
Default constructor for an exception handler that rethrows. More... | |
ExceptionSink (ExceptionHandler &eh, ExceptionSource *source) noexcept | |
Constructor. More... | |
ExceptionSink (ExceptionHandler *eh, ExceptionSource *source) noexcept | |
Constructor. More... | |
ExceptionSink (std::nullptr_t, ExceptionSource *)=delete | |
Deleted override to prohibit a null ExceptionHandler. | |
ExceptionHandler * | eh () const noexcept |
Returns the exception handler pointer. More... | |
ExceptionSource * | esrc () const noexcept |
Returns the exception source pointer. More... | |
void | call (std::exception &e, bool done) |
Calls the exception handler's onException() method. More... | |
void | reset () noexcept |
Resets the object as if default constructed. More... | |
bool | set () const noexcept |
Returns true if eh() is not null. More... | |
Static Public Member Functions | |
static ExceptionSink | logOnly () |
A factory function for an exception handler that logs the exception as an error but does not re-throw. More... | |
static ExceptionSink | rethrow () |
A factory function for an exception handler that rethrows. More... | |
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
The EventEmitter and TimerList classes associate an event handler and ExceptionSink with each event source (file descriptor or timer). If the event handler throws an exception then the associated ExceptionHandler's onException() method is called, via ExceptionSink::call().
An onException() implementation normally just rethrows the exception to terminate the event loop, but sometimes the exception can be handled less drastically, perhaps by deleting the object identified as the exception source.
For example, Server objects create and contain ServerPeer objects:
The ExceptionSinkUnbound class is used as a device to force factory methods to plumb-in an ExceptionSource pointer to the newly-created object as soon as its address is available (ie. before the constructor body runs).
So then the ServerPeer constructor has a bound ExceptionSink that it can pass to its timers and other event-handling objects:
Definition at line 100 of file gexceptionsink.h.
|
defaultnoexcept |
Default constructor for an exception handler that rethrows.
Postcondition: !set()
|
noexcept |
Constructor.
The ExceptionHandler reference must remain valid as the ExceptionSink is copied around. Postcondition: set()
Definition at line 47 of file gexceptionsink.cpp.
|
noexcept |
Constructor.
The ExceptionHandler pointer must remain valid as the ExceptionSink is copied around. Precondition: eh != nullptr Postcondition: set()
Definition at line 53 of file gexceptionsink.cpp.
void GNet::ExceptionSink::call | ( | std::exception & | e, |
bool | done | ||
) |
Calls the exception handler's onException() method.
Used by EventEmitter and TimerList when handling an exception thrown from an event handler. Precondition: set()
Definition at line 82 of file gexceptionsink.cpp.
|
noexcept |
Returns the exception handler pointer.
Definition at line 72 of file gexceptionsink.cpp.
|
noexcept |
Returns the exception source pointer.
Definition at line 77 of file gexceptionsink.cpp.
|
static |
A factory function for an exception handler that logs the exception as an error but does not re-throw.
This can be a convenient alternative to a try/catch block for code that might throw but should not terminate a long-running server process.
Definition at line 59 of file gexceptionsink.cpp.
|
noexcept |
Resets the object as if default constructed.
Postcondition: !set()
Definition at line 88 of file gexceptionsink.cpp.
|
static |
A factory function for an exception handler that rethrows.
Definition at line 66 of file gexceptionsink.cpp.
|
noexcept |
Returns true if eh() is not null.
Definition at line 94 of file gexceptionsink.cpp.