Write short notes in throwing an exception .
Throwing an Exception
In C#, it is possible to throw an exception programmatically. The 'throw' keyword is used for this purpose. The general form of throwing an exception is as follows.
For example, the following statement throws an ArgumentException explicitly.
- throw new ArgumentException("Exception");
-
- //C#: Exception Handling:
- using System;
- class MyClient
- {
- public static void Main()
- {
- try
- {
- throw new DivideByZeroException("Invalid Division");
- }
- catch (DivideByZeroException)
- {
- Console.WriteLine("Exception");
- }
- Console.WriteLine("LAST STATEMENT");
- }
- }