Runtime errors occur at the time the program executes and can't be corrected. A programmer can, however, take preventive measures while coding the program, to handle runtime errors with the help of the try, catch, and finally keywords.
using System;
using System.Collections.Generic;
using System.Text;
namespace exception
{
class Program
{
public static void Main()
{
try
{
throw new DivideByZeroException("Invalid Division");
}
catch(DivideByZeroException e)
{
Console.WriteLine("Exception" );
Console.ReadLine();
}
Console.WriteLine("Final Statement that is executed");
Console.ReadLine();
}
}
}
|