Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Throwing Exception

What is the purpose of throwing exceptions in catch block.
Bcos the exception is already thrown only, it is coming to the catch block.What is the purpose of throwing it again then!!!.....Help

Monday, August 16, 2004

To allow the method's caller to catch it again.

Chris Nahr
Monday, August 16, 2004

And also you can throw a new exception that may be more appropriate.

Writers of class libraries must not, of course, forget to wrap the original in the new exception. A crime the writers of the .NET FCL are often guilty of.

Monday, August 16, 2004

Another reason: if, for example, it's a SqlException and you only want to handle a particular error # there. Otherwise, throw the error up to the calling method.

Brian Kavanaugh
Monday, August 16, 2004

Another reason is if you want to catch all exceptions except a specific type, e.g. if you want to catch any exception except a SecurityException

catch(Exception ex)
  ... handle it

Friday, September 3, 2004

*  Recent Topics

*  Fog Creek Home