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 are the Types of objects in ASP
What is the use of execute non query in asp.net?
What is custom attribute?
What is the recommended approach for asp.net mvc to globally intercept exceptions? What other functionality can be implemented with the approach? : Asp.Net MVC
How does the cookies work in asp.net?
What is connection pooling and how to enable and disable connection pooling?
Which browsers support the xmlhttprequest object?
How many validators do ASP.NET have?
What is smpte vc-1?
What is the difference between ldap and active directory?
What is __ requestverificationtoken?
How you can add an event handler?
List the major built-in objects in asp.net?
What are server-side comments in ASP.NET?
Describe the diffeerence between inline and code behind - which is best in a loosely coupled solution?