Reputation: 1686
I have this simple program demonstrating exception handling in .NET, i am catching the ArgumentOutOfRangeException
in this case, but the custom message that i pass to the console is not getting displayed.
using System;
class program
{
static void Main()
{
int[] source = { 1, 2, 3, 4, 5 };
int[] destination = { 6, 7, 8, 9 };
try
{
Array.Copy(source, destination, 7);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("Sorry, there is something wrong in the program ! : {0}", e.Message);
}
}
}
and here is the output screenshot
Upvotes: 1
Views: 394
Reputation: 887479
You're catching ArgumentOutOfRangeException
, but the method is throwing an ArgumentException
.
Therefore, your catch
block never executes.
Upvotes: 8