Notifications
 
Answer using your Joblagao account
 
Close

Leave your answer

 
or answer with facebook account
 
Arvind Vishwakarma answered| May 21, 2014

In this program we divide by zero.

Sadly this results in a DivideByZeroException.

 

Try:

We use the try and catch blocks to structure our error handling. This may lead to cleaner code.

 

Based on:

 

.NET 4.5

 

Program that throws an exception: C#

 

using System;

 

class Program

{

    static void Main()

    {

try

{

   int value = 1 / int.Parse("0");

   Console.WriteLine(value);

}

catch (Exception ex)

{

   Console.WriteLine(ex.Message);

}

    }

}