Exception

uC++ EHM

The Exception Handling Mechanism (EHM) in uC++ is the hub for everything exception-related — it pulls together exception types, both kinds of raises, both kinds of handlers, and propagation to other coroutines/tasks.

Why does uC++ need its own EHM instead of using C++'s?

Plain C++ only supports throw/catch — one raise, one handler kind, no way to target another stack. uC++ adds resumption (recover without unwinding), nonlocal raise (_At another execution), and a restricted exception-type system (_Exception), because in a concurrent OO environment you need all four pieces: multiple stacks, optional repair, type safety for matching, and propagation that respects destructors.

Defining features

  • Exceptions must be generated from a type defined by _Exception.
  • Two raising mechanisms: throw (termination) and resuming (resumption).
  • Two handler kinds: catch (termination) and _CatchResume (resumption) — each matches only its own raise kind.
  • Supports propagation of nonlocal and concurrent exceptions.
  • All exception types (user, runtime, I/O) are grouped into a hierarchy rooted at uBaseException.

Exception type

_Exception E { ... };         // like a class
E e;                          // local
E * ep = new E;               // dynamic
_Resume *ep;  delete ep;
_Throw E();                   // temporary

An exception type has all the properties of a class and must have a public default and copy constructor.

Inherited members (from uBaseException)

class uBaseException {
    uBaseException( const char * msg = "" );
    const char * message() const;       // std::exception::what
    const uBaseCoroutine & source() const;
    const char * sourceName() const;
    virtual void defaultTerminate();    // called if _Throw unhandled
    virtual void defaultResume();       // called if _Resume unhandled
};

defaultTerminate forwards an UnhandledException to the resumer/joiner; defaultResume throws the exception (degrading a _Resume to a _Throw).

The 4 pieces

EHM = Exception Type + Raise + Propagation + Handlers.