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
*/
Loading

Abhishek JainRank #1,062 · 1.8K reputationPosted Sep 18, 2013, 6:01 AM EDT
Regards
AJ
Joxin Stanly181 reputationPosted Sep 18, 2013, 6:30 AM EDT
in the above example, the purpose of Data property is illustrated.
It gives developers flexibility to store additional data.
Hope this helps....
Posted Sep 18, 2013, 12:29 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 18, 2013, 7:53 PM EDT
hi,
When ever an exception is thrown, the CLR looks for catch block statement to handle the exception. If no catch block found than the CLR display unhandled exception message to user and stop execution of program.
In your code there is no execution so it give same output.
hope this will help you.
Posted Sep 19, 2013, 4:34 AM EDT