Exception Handling in C#
An exception is defined as an event that occurs during the execution of a program that is unexpected by the program code. The actions to be performed in case of occurrence of an exception is not known to the program. In such a case, we create an exception object and call the exception handler code. The execution of an exception handler so that the program code does not crash is called exception handling. Exception handling is important because it gracefully handles an unwanted event, an exception so that the program code still makes sense to the user. Keyword Definition try Used to define a try block. This block holds the code that may throw an exception. catch Used to define a catch block. This block catches the exception thrown by the try block. finally Used to define the finally block. This block holds the default code. throw Used to throw an exception manually. Let us take a simple example to understand what an exception is: // C# program to show how // Exceptions occur...