uC++ EHM

Object Binding (Exception)

When a member function raises with _Resume or _Throw, uC++ implicitly stores the this pointer of the raising object into the exception — the exception carries “which object raised me” alongside its type.

Why bind the object to the exception?

So a handler can say “I only want E from this particular object”, not “I want E from anywhere.” Without object binding, if two Obj instances both raise the same E, a single catch(E) can’t distinguish them — you’d need a flag variable stuffed inside E to tell them apart. Object binding makes the handler match at the language level via bound handlers.

The rules

  • For a member raise, the binding is this.
  • For a static member or free routine, there is no binding (no this).
  • For a nonlocal raise (_Resume ... _At c), the binding is the coroutine/task object executing the raise.

Example

_Exception E {};
struct Obj {
    void mem() { ... _Throw E{}; ... }   // implicitly stores 'this' into the exception
};
int main() {
    Obj obj1, obj2;
    try {
        ... obj1.mem(); ... obj2.mem(); ... _Throw E{};
    } catch( obj1.E ) {     // only matches E raised from obj1
    } catch( obj2.E ) {     // only matches E raised from obj2
    } catch( E ) {          // catch-any E (including the free _Throw E{})
    }
}

The catch( obj1.E ) and catch( obj2.E ) are bound handlers — they only match when the stored this equals &obj1 or &obj2 respectively.