Hi friends,
I want to know that how will we handle exception without using try, catch and finally? Anyone give an explanation that how it is possible to do that?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Feb 13, 2012, 12:09 PM
If error is infrequent (that is exception) you have to use try catch. Less than 30% is infrequent.
Traditional Error Handling Methods example:
using System;
public class MathErrorPreventedWithIf
{
public static void Main()
{
int num, denom, result;
DataEntry(out num, out denom);
if (denom != 0)
result = num / denom;
else
{
Console.WriteLine("Attempt to divide by 0. Denominator replaced with 1");
result = num / 1;
}
Console.WriteLine("Result is {0}", result);
}
public static void DataEntry(out int num, out int denom)
{
Console.Write("Enter a number ");
num = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number to divide into the first ");
denom = Convert.ToInt32(Console.ReadLine());
}
}
VulpesPosted Feb 13, 2012, 11:34 AM
http://www.c-sharpcorner.com/Forums/Thread/132543/exception-without-try-catch.aspx