Exception Parameters
Exception parameters pass information from the raise site to the handler β how this is done depends on the EHM, but in C++/uC++/Java they live as fields of the exception type.
Why do we need parameters at all?
Two reasons. First, the handler needs context (βoverflow of what value?β) to do anything useful. Second β and this is the payoff for resumption β the handler can modify a field through a reference or pointer to fix the problem at the raise site before the raiser resumes.
Passing info to the handler (termination style)
struct E {
int i;
E( int i ) : i(i) {}
};
void f( ... ) { ... throw E( 3 ); ... } // argument
int main() {
try { f( ... ); }
catch( E p ) { // parameter, by value or reference
... p.i ...
}
}Fix-up at the raise site (resumption style)
For resumption, store a reference/pointer in the exception so the handler can modify values that the raiser sees when control returns:
_Exception E {
public:
int & r; // reference to raiser's local
E( int & r ) : r( r ) {}
};
void f() {
int x;
... _Resume E( x ); ... // handler can modify x through e.r
}
void g() {
try {
f();
} _CatchResume( E & e ) {
... e.r = 3; ... // fixup β f sees x == 3 after _Resume returns
}
}Call-stack flow: g calls f β _Resume E propagates up β _CatchResume runs, sets e.r = 3 β control returns to the raise site, x is now 3.