Alex Rivera | Logout

Throw an exception in try catch block

Asked 2010-07-20T19:34:00.327
27
try { 
  if (isFileDownloaded)
   // do stuff
  else
   throw new ApplicationException()
} 
catch (Exception e)
{
  // something went wrong to save the error to log
}
finally
{
  //release resources
}

My question is would the catch catches the ApplicationException thrown in the try block? is it in poor coding style?

Should it be written in another way?

Edit
Report

1 Answer

1

Yes the catch would catch your ApplicationException and yes is is poor coding style. As a good general rule only catch specific exception and those that you are going to do something with, like fixing up application state.

answered 2010-07-20T19:38:24.280

Your Answer