We help IT Professionals succeed at work.

Is this correct throw-catch?

Camillia
Camillia asked
on
Not sure if I'm doing this correctly.

private void SaveRecords()
{

  try

   {
      Return.Save();
   }

  catch

   {
     //log to file here
   
     ..

    ///display error to user
     message.Show("error");

   }

}


In return class:


private void SaveRecords()
{

  try

   {
      Return.Save();
   }

  catch (Exception e)

   {
     throw e;
   

   }

}
Comment
Watch Question

Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT
Commented:
U posted the wrong code of Return class.

But the try catch looks fine.
CERTIFIED EXPERT
Commented:
When your looking gor Try Catch, block it's not advised to place all the code inside Try Catch, Which will reduce teh performace as the applicationa s have to track and keep all the steps involved in eecution to capture details.

So Try to narrow down with the exception which you feel as will occur and what's remedy needs to be done, Whcih will help to solve the unexpected problem with the real solutiona sthe Geenric Catch will not help to solve the problem at development. Even the amoutn of data logged by the general exception object is more than Specific exception.

Take a look into the MSDN blog for more details
http://msdn.microsoft.com/en-us/library/seyhszts(v=vs.100).aspx
CERTIFIED EXPERT

Author

Commented:
But that "throw" is ok? I will look into non-generic exception

Explore More ContentExplore courses, solutions, and other research materials related to this topic.