uC++ EHM

Bound Handler

A bound handler catches an exception only when the raising object is a specific instance — the handler is qualified with object . in front of the exception type.

Why not just compare IDs inside the handler body?

You could stuff an identifier into the exception and check it inside catch(E) { if (e.id == myId) ... else throw; }, but that’s a flag variable in disguise and it breaks propagation matching — every handler for E gets entered, then filters. Bound handlers push the match down to the propagation mechanism so non-matching frames are skipped, which is both cleaner and faster.

Syntax

catch       ( raising-object . exception-declaration ) { ... }
_CatchResume( raising-object . exception-declaration ) { ... }

Matching rule

An exception is caught when both conditions hold:

  1. The bound object (stored implicitly by object binding) equals the handler’s raising-object.
  2. The raised exception type matches the handler’s declaration (same type or a base type).

The catch-any handler catch(...) has no bound form — it’s for unqualified generality.

Example

_Exception E {};
struct Obj {
    void mem() { ... _Throw E{}; ... }   // 'this' stored into E
};
int main() {
    Obj obj1, obj2;
    try {
        obj1.mem();
        obj2.mem();
        _Throw E{};                       // no binding (free raise)
    } catch( obj1.E ) { /* only from obj1 */ }
      catch( obj2.E ) { /* only from obj2 */ }
      catch( E )      { /* any E, including the free one */ }
}