Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throwing exceptions in ASP.NET C#

Tags:

Is there a difference between just saying throw; and throw ex; assuming ex is the exception you're catching?

like image 674
Chris Westbrook Avatar asked Sep 17 '08 22:09

Chris Westbrook


People also ask

What is throwing an exception in C#?

Exceptions are used to indicate that an error has occurred while running the program. Exception objects that describe an error are created and then thrown with the throw keyword. The runtime then searches for the most compatible exception handler.

What is throwing an exception?

The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

How do you handle exceptions in asp net?

NET Framework, an exception is an object that inherits from the System. Exception class. An exception is thrown from an area of code where a problem has occurred. The exception is passed up the call stack to a place where the application provides code to handle the exception.

Does throwing exception return C#?

After throwing an exception, you do not need to return because throw returns for you. Throwing will bubble up the call stack to the next exception handler so returning is not required.


1 Answers

throw ex; will erase your stacktrace. Don't do this unless you mean to clear the stacktrace. Just use throw;

like image 135
GEOCHET Avatar answered Nov 10 '22 22:11

GEOCHET