Answer: An exception can be raised using th Throw keyword. You have to use this try statement within your exception-handling structure, which passes the control flow to the catch statement when an exception occurs.
Example:
using System;
class HandledException
{
public static void Main()
{
int x = 0;
int intTemp = 0;
try
{
intTemp = 100/x;
Console.WriteLine(?Program terminated before this statement?);
}
catch(DivideByZeroException de)
{
Console.WriteLine("Division by Zero occurs");
}
finally
{
Console.WriteLine("Result is {0}", intTemp);
}
}
}
Asked In: Many Interviews |
Alert Moderator