| Author: Antony s Nasarath 05 Oct 2008 | Member Level: Silver | Rating: Points: -20 |
Hi,
You can use try-catch-finally block to handle any error.
Pl see the sample code below and it might give some idea.
public class EHClass { static void Main() { try { //Your code goes here Console.WriteLine("Executing the try statement."); throw new NullReferenceException(); }
//Catch known exception and do something catch (NullReferenceException e) { Console.WriteLine("{0} Caught exception #1.", e); } //Catch the exception object catch(Exception ex) { Console.WriteLine("Caught exception #2."); } finally { Console.WriteLine("Executing finally block."); } } }
The excepiton object ex as in catch(Exception ex) would give more detail like error msg, errorTrace etc..
Cheers
|