Throw exception

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

What is the difference between:

catch(Exception e)
{ throw e; }

and

catch(Exception e)
{ throw; }
 
Curious said:
What is the difference between:

catch(Exception e)
{ throw e; }

and

catch(Exception e)
{ throw; }

The first form creates a new stack trace from the point of throwing;
the second form preserves the stack trace of the original expection. I
find the second form is almost always more useful, unless you're
actually trying to hide the internals of your code.
 
What if I want both the info about what happened earlier and what
happened from that point on?
 
Curious said:
What if I want both the info about what happened earlier and what
happened from that point on?

What do you mean by "from that point on"? You're throwing an exception
- you either get:

Top level
Second level
Level you catch at
Level below
Bottom level

(with throw)

or

Top level
Second level
Level you catch at

(with throw e)
 
Back
Top