Exception Handling in C#.Net

Exceptions are unexpected events that might occur while executing the program. We need to handle such exceptions properly in order to run the program without any issues.

C# provides Java-type mechanism to handle the exceptions in the code.

try{

//code that might throw exception.

}

catch(Exception ex){

//Do some recovery operation here.

}

finally{

//This code is always executed even when exception is not thrown.

}

You may also like...