[LC++]exceptions out off class

Jack Lloyd lloyd at acm.jhu.edu
Tue Jul 16 00:53:06 UTC 2002


On Mon, 15 Jul 2002, Julien Patrick Claassen wrote:

> Hello!
>   I have a general problem. I tried to get my experience with exceptions a
> little bit better again. So I wrote a testprogramm. It compiled fine, but
> it seg.fualts. Asume thefollowing:
>   There's a simple exception-class with a member function getString() and
> of course a string itss. Then there is a function test, which just throws
> the exception.
>   In the main-programm I then try to catch it. If I just catch it like:
> catch (my_exception)
> it works. But if I catch it like:
> catch (my_exception e) OR
> catch (my_exception& e)
> it segfaults.
>   If I throw the exception in main and catch it there, everything works
> fine in all three ways.
>   Does passing exception by reference or by value only work if you do it
> out of a class?

Not that I know of (that would be a horrible flaw, since in general you
don't know where exactly an exception was thrown from). I always catch my
exceptions as a named reference [so I can get the error string inside], and
have never had a problem such as this.

Could you post your code? I'd like to take a look if you don't mind.

-Jack





More information about the tuxCPProgramming mailing list