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
Why we use asp.net for website development?
What is a server cookie?
How to disable disable browser's Back button in asp.net (JavaScript)?
Describe the method to create a permanent cookie?
How to create events for a control?
How ASP and ASP.NET page works? Explain about asp.net page life cycle?
Write a code for sending an email from asp.net application.
How do you do Client-side validation in .Net?
How to implement globalization and localization in the use interface in .net.
Explain the different parts that constitute ASP.NET application?
What is the difference between web.config and machine.config in ASP.NET?
What does session_start () do?
Can we store object in viewstate?
What are the ways of preserving data on a Web Form in ASP.NET?
Explain the difference between server control and html control.