Regarding Throw keyword
Why we use throw keyword in exception handling if we can work with try and catch blocks too.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 13, 2011, 9:14 PM EDT
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
}