Regarding Throw keyword
Why we use throw keyword in exception handling if we can work with try and catch blocks too.
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.
Prabhu RajaPosted Sep 14, 2011, 1:14 AM
try and Catch blocks will throw Error automatically, is any runtime error occurs.
And Throw keyword is used to used to throw an exception programmatically in C#.Net. The Programmer can throw an exception to Catch block, for an example is an condition is not met.
try
{
int n=5, m=0;
if (m>0)
{
int c = n/5;
}
else
{
thorw new DivideByZeroException("Invalid Division");
}
}
Catch(DivideByZeroException ex)
{
MessageBox.WriteLine("Invalid Dividion Found");
}
--------------------------------------------------------------------
If this helpful, then mark as "Correct Answer"
Thank you
}