How many types of expection in c#

Exception is an event that occur during the execution of program that disrupts the normal flow of them program. When an exception occur its object are created by the method in which an exception occurs, which is handle by the default exception handler. The object contains all the details of the exception and its type etc.

Exception Handler is a code that executes when exception is occurs. The run-time handler search the call stack to find the appropriate method containing the code for exception and after receive suitable solution then handle all the exception, and generate accurate message on the screen. Mostly exception class is the sub-class of Throwable class .

Type of Exception:

In Any programming language, there are basically two types of exceptions first is checked and another is unchecked where error is considered as unchecked exception.

  1.  Checked Exception (Compile Time Exception)
  2.  Unchecked Exception (Run Time Exception )
  3.  Error

Checked Exception:

Those exceptions are called checked exception which occur at compile time. So for this reason it is also called compile time exceptions. These types of exceptions cannot be ignored at the compile time, it should be necessary to handle it. If a program is throwing a checked exception at compile time then it should handle using try-catch block and declare the exception using throw keyword, otherwise the program will give a compilation error.

Example of checked Exception- FileNotFoundException.

Unchecked Exception

Those exceptions are called unchecked exception that are not handle at compile time. It means if your program is throwing an unchecked exception at run-time and even if you didn’t handle that exception then program won’t give a compilation error. Mostly these types of exception occurs due to the bad data provided by the user during the user-program interaction. It is also known as run time exceptions.

Some Example of unchecked Exception-

  • ArithmeticException,
  •  NullPointerException
  •  ArrayIndexOutOf BoundException
  •  IllegalArgumentException
  •  NumberFormatException etc.

Leave a Reply

Your email address will not be published. Required fields are marked *