Maha

Maha

  • NA
  • 0
  • 328.4k

Exception handling

Sep 18 2013 9:50 AM
http://www.dotnetperls.com/exception

Following program is given in the above website (3rd program). Without try and catch it is giving the same output. So what is the purpose of using try and catch.

using System;
using System.Collections;

class Program
{
static void Main()
{
//try
//{
// Create new exception.
var ex = new DivideByZeroException("Message");
// Set the data dictionary.
ex.Data["Time"] = DateTime.Now;
ex.Data["Flag"] = true;
// Throw it!
//throw ex;
//}
//catch (Exception ex)
//{
// Display the exception's data dictionary.
foreach (DictionaryEntry pair in ex.Data)
{
Console.WriteLine("{0} = {1}", pair.Key, pair.Value);
}
//}
Console.ReadKey();
}
}
/*
Time = 18/09/2013 9:34:38 AM
Flag = True
*/


Answers (5)