2. Exception
• A problem that arises during the execution of a program
• In C#, Exception Handling is a response to an exceptional
circumstance that arises while a program is running
• Eg:- an attempt to divide by zero
3. Example
Num1 = 10 Divided Num2 = 0
Answer = Infinity
Exception Occurs
IF
Handled
Not
Handled
Not
Terminated
Terminated
4. • C# exception handling is built upon four keywords
try
catch
finally
throw
• Syntax
try
{
// Statement which can cause an exception.
}
catch(Type x)
{
// Statements for handling the exception
}
finally
{
//Any cleanup code
}