March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System;
namespace Samples
{
public class ExceptionSample
{
public static void Main()
{
try
{
DivideBy(42, 0);
}
catch(Exception e)
{
Console.WriteLine("Exception caught:");
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Stack trace: {0}", e.StackTrace);
Console.WriteLine("Inner exception (if any): {0}",
e.InnerException);
}
}
public static int DivideBy(int i, int j)
{
try
{
return i / j;
}
catch(DivideByZeroException e)
{
throw new DivideByZeroException(
"Parameter j cannot be zero",
e);
}
}
}
}
Exception caught: Message: Parameter j cannot be zero Stack trace: at Samples.ExceptionSample.DivideBy(Int32 i, Int32 j) in C:\Books\BCL \Samples\System\Exception\Exception.cs:line 30 at Samples.ExceptionSample.Main() ...
Read now
Unlock full access