Is this correct throw-catch?

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;
   

   }

}
LVL 7
CamilliaAsked:
Who is Participating?
 
santhimurthydConnect With a Mentor 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
0
 
informaniacConnect With a Mentor Commented:
U posted the wrong code of Return class.

But the try catch looks fine.
0
 
CamilliaAuthor Commented:
But that "throw" is ok? I will look into non-generic exception
0
All Courses

From novice to tech pro — start learning today.