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.WriteLi ne("Before exception is generated");
//generate an index out-of-bounds exception
for (int i = 0; i < 10; i++)
{
nums[i] = i;
Console.WriteLi ne("nums[{0}] : {i}", i, nums[i]);
}
Console.WriteLi ne("this won't be displayed");
}
}
class ExcDemo2
{
public static void Main()
{
try
{
ExcTest.genExce ption();
}
catch (IndexOutOfRang eException)
{
//catch the exception
Console.WriteLi ne("Index out-of-bounds!");
}
Console.WriteLi ne("After catch statement.");
}
}
what's supposed to happen is that calling ExcTest.genExce ption() 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.WriteLi ne("Before exception is generated");
//generate an index out-of-bounds exception
for (int i = 0; i < 10; i++)
{
nums[i] = i;
Console.WriteLi ne("nums[{0}] : {i}", i, nums[i]);
}
Console.WriteLi ne("this won't be displayed");
}
}
class ExcDemo2
{
public static void Main()
{
try
{
ExcTest.genExce ption();
}
catch (IndexOutOfRang eException)
{
//catch the exception
Console.WriteLi ne("Index out-of-bounds!");
}
Console.WriteLi ne("After catch statement.");
}
}
what's supposed to happen is that calling ExcTest.genExce ption() 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
Comment