Andrey Tarasevich
9/16/2008 7:50:00 PM
Ruben wrote:
> I'm struggling with the throw and catch exception system. As I understood
> it, when you throw an error, that the stack is searched for a matching
> catch, but I'm having difficult finding where to put a catch that can be
> found by all the methods in a class.
There's no way to create a 'catch' that will catch exceptions thrown "by
all the methods in a class". The search for the matching handler is not
in any way tied to the type definitions or their relationships.
The term "stack" (the one that's searched for the handler) refers to the
run-time execution stack the way it looked at the moment when the
exception was thrown, i.e. "stack" is the sequence of nested function
contexts leading from 'main' to the 'throw' in question.
> Can't I include a try{}catch in a
> constructor and then expect it to be found by throws which are littered
> throughout my object?
No, that's completely unrelated.
> Also, if I have an class object within my class in a hasa relationship,
> can the included object reach throw things to the enclosed object, or is
> that another space altogether unless real inheritance is used?
Same thing. The search for the matching handler is not in any way tied
to the data structures. It has nothing to do with inheritance or any
other relationships, like 'has-a'. As stated above, it is defined by the
run-time sequence of function call contexts.
--
Best regards,
Andrey Tarasevich