What will be output of following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JUSTFORFUN
{
class Program
{
static void Main(string[] args)
{
try
{
int a = 10;
int b = 0;
int c = a / b;
}
catch (NullReferenceException ex2)
{
Console.WriteLine("generic exception with msg :" + ex2.Message);
}
catch (DivideByZeroException ex1)
{
Console.WriteLine("generic exception with msg :" + ex1.Message);
}
catch (Exception ex)
{
Console.WriteLine("generic exception with msg :" + ex.Message);
}
finally
{
Console.Read();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JUSTFORFUN
{
class Program
{
static void Main(string[] args)
{
try
{
int a = 10;
int b = 0;
int c = a / b;
}
catch (NullReferenceException ex2)
{
Console.WriteLine("generic exception with msg :" + ex2.Message);
}
catch (DivideByZeroException ex1)
{
Console.WriteLine("generic exception with msg :" + ex1.Message);
}
catch (Exception ex)
{
Console.WriteLine("generic exception with msg :" + ex.Message);
}
finally
{
Console.Read();
}
}
}
}
Output : generic exception with msg : Attempted to divide by zero
Now what will be the out put of following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JUSTFORFUN
{
class Program
{
static void Main(string[] args)
{
try
{
int a = 10;
int b = 0;
int c = a / b;
}
catch (Exception ex)
{
Console.WriteLine("generic exception with msg :" + ex.Message);
}
catch (NullReferenceException ex2)
{
Console.WriteLine("generic exception with msg :" + ex2.Message);
}
catch (DivideByZeroException ex1)
{
Console.WriteLine("generic exception with msg :" + ex1.Message);
}
finally
{
Console.Read();
}
}
}
}
Output ; Build Error 1 A previous catch clause already catches all exceptions of this or of a super type ('System.Exception')
Comments
Post a Comment