G
Guest
Hi folks,
I'm working on code from Herb Schildt's book in which he says that an
exception can be thrown by one method and caught by another
class ExcTest
{
public static void genException()
{
int[] nums = new int[4];
Console.WriteLine("Before exception is generated");
//generate an index out-of-bounds exception
for (int i = 0; i < 10; i++)
{
nums = i;
Console.WriteLine("nums[{0}] : {i}", i, nums);
}
Console.WriteLine("this won't be displayed");
}
}
class ExcDemo2
{
public static void Main()
{
try
{
ExcTest.genException();
}
catch (IndexOutOfRangeException)
{
//catch the exception
Console.WriteLine("Index out-of-bounds!");
}
Console.WriteLine("After catch statement.");
}
}
what's supposed to happen is that calling ExcTest.genException() will
generate the exception in genExcetpion (which has no exception handling) and
so will therefore be handled in the caller Main() which does!
however all I get is Visual studio 2005 intruding into this scenario with an
over-detailed exception dialog box that highlights the offending line in
yellow and goes into debug mode.
is there a way I can get Main() to handle to the exception without having
VStudio intrude, is there some setting somewhere?
Regards, and thanks in advance,
CharlesA
I'm working on code from Herb Schildt's book in which he says that an
exception can be thrown by one method and caught by another
class ExcTest
{
public static void genException()
{
int[] nums = new int[4];
Console.WriteLine("Before exception is generated");
//generate an index out-of-bounds exception
for (int i = 0; i < 10; i++)
{
nums = i;
Console.WriteLine("nums[{0}] : {i}", i, nums);
}
Console.WriteLine("this won't be displayed");
}
}
class ExcDemo2
{
public static void Main()
{
try
{
ExcTest.genException();
}
catch (IndexOutOfRangeException)
{
//catch the exception
Console.WriteLine("Index out-of-bounds!");
}
Console.WriteLine("After catch statement.");
}
}
what's supposed to happen is that calling ExcTest.genException() will
generate the exception in genExcetpion (which has no exception handling) and
so will therefore be handled in the caller Main() which does!
however all I get is Visual studio 2005 intruding into this scenario with an
over-detailed exception dialog box that highlights the offending line in
yellow and goes into debug mode.
is there a way I can get Main() to handle to the exception without having
VStudio intrude, is there some setting somewhere?
Regards, and thanks in advance,
CharlesA