usage of try catch

Posted by Muhammed Rauf K on Stack Overflow See other posts from Stack Overflow or by Muhammed Rauf K
Published on 2011-06-21T14:08:33Z Indexed on 2011/06/21 16:22 UTC
Read the original article Hit count: 403

Filed under:
|

Which is best: Code Snippet 1 or Code Snippet 2 ? And Why?

/* Code Snippet 1
 * 
 * Write try-catch in function definition
 */
 void Main(string[] args)
 {
     AddMe();
 }

 void AddMe()
 {
     try
     { 
         // Do operations...
     }
     catch(Exception e)
     {
     }
 }

/* Code Snippet 2
 * 
 * Write try-catch where we call the function.
 */
 void Main(string[] args)
 {
     try
     {
         AddMe();
     }
     catch (Exception e)
     {
     }
 }

 void AddMe()
 {
     // Do operations...
 }

© Stack Overflow or respective owner

Related posts about c#

Related posts about try-catch