Can we throw exception from catch block ?
Answer Posted / arjun
The exceptions, which we caught inside a catch block, can
re-throw to a higher context by using the keyword throw
inside the catch block. The following program shows how to
do this.
//C#: Exception Handling: Handling all exceptions
using System;
class MyClass
{
public void Method()
{
try
{
int x = 0;
int sum = 100/x;
}
catch(DivideByZeroException e)
{
throw;
}
}
}
class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
try
{
mc.Method();
}
catch(Exception e)
{
Console.WriteLine("Exception caught here" );
}
Console.WriteLine("LAST STATEMENT");
}
}
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is the difference between user control an custom control?
What is owin authentication?
What are uri parameters?
When you are running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?
What should you do is you want to remove an existing component but would like to make some funtionalities?
Is asp.net web forms dead?
Explain the difference between codebehind="mycode.aspx.cs" and src="mycode.aspx.cs"?
How do I publish my asp.net application to my isp's web server?
What is the use of session in web application?
How would you get asp.net running in apache web servers?
What are the different types of proxy patterns?
What is inheritance and an how it be used, example with an example?
Can user control be stored in library?
Explain model, view and controller represent in an mvc application? : asp.net mvc
What is the difference between rest and restful?