Hi all,
Why am I getting a null value to the InnerException object?
namespace InnerException
{
class D
{
public static int Divide(int i, int j)
{
if (j == 0)
throw new DivideByZeroException("Division by zero is
forbidden.");
return i / j;
}
}
class Program
{
static void Main(string[] args)
{
try
{
int i = int.Parse (Console.ReadLine());
int j = int.Parse(Console.ReadLine()); // enter a 0
value
Console.WriteLine(D.Divide (i , j));
}
catch (Exception ex)
{
if (ex.InnerException != null)
Console.WriteLine("Inner Exception: " +
ex.InnerException.ToString());
else
Console.WriteLine(ex.Message);
}
}
}
}
sample I/O
========
2
0
Division by zero is forbidden.
Can anyone elaborate using examples?
Thanks in advance,
Muler