Jonathan Biggar wrote:
> ke_jin@[EMAIL PROTECTED]
wrote:
> > Jonathan Biggar wrote:
> >> Just write your own wrapper function that calls non_existent(),
catches
> >> the exceptions you want, and returns different error codes for
different
> >> exceptions. Once you've done that, you can reuse that code
everywhere
> >> without having to write lots of catch() blocks.
> >
> > Then, you would end up with exactly same "lots of" switch/case blocks
> > :).
>
> Not if you design the error codes right, or make predicate functions
> that you can reuse that translate the error code to a boolean value.
>
As long as your wrapper "returns different error codes for different
exceptions".
Here is an example:
original code with many try/catch:
try {
....
}
catch(exception a) {
handle_exception_a(...);
}
catch(exception b) {
handle_exception_b(...);
}
...
wrapper that "returns different error codes for different exceptions":
....
int wrapper() {
...
try {
....
}
catch(exception a) {
return error_code_a;
}
catch(exception b) {
return error_code_b;
}
...
}
Use of this wrapper:
...
switch(wrapper()) {
case error_code_a: handle error a; break;
case error_code_b: handle error b; break;
...
}
Regards,
Ke
> --
> Jon Biggar
> Floorboard Software
> jon@[EMAIL PROTECTED]
> jon@[EMAIL PROTECTED]


|