I tried to implement that code:
try
{
CheckDivideByZero(num1, num2);
}
catch (FirstDivideByZeroException)
{
Console.WriteLine("first number is zero");
}
I need that, FirstDivideByZeroException class will handle that Exeption instead of DevideByZeroExeption.
I tried to do that:
public class
FirstDivideByZeroException : DivideByZeroException {}
but when i run the application, that message appear:
"An unhandled exception of type 'System.DivideByZeroException' occurred .."
How can i implement that?
How can implement class which derived from system.exeption?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
sudheer panwar19 pointsPosted Jan 31, 2006, 1:24 AM EST
try { try { DivideByZero(num1,num2); } catch(DivideByZeroException ex) { throw new CustomDivideByZeroException("Custom error :: " + ex.Message); } } catch(CustomDivideByZeroException exx) { MessageBox.Show(exx.Message); } ***** public class CustomDivideByZeroException:System.Exception { public CustomDivideByZeroException():base() {} public CustomDivideByZeroException(string message):base(message) {} public CustomDivideByZeroException(string message , Exception ex):base(message,ex) { } } if anybody know better solution plz post it here.