Throw Exception Vs Throw New Exception

K

Kerri

Hi,

I am new to .NET

In my Error Logic on my Aspx pages when an error happens
it hits my catch statement where I throw an Exception.

My question is :

what is the difference between Thwo Exception and Throw
New Exception?

Anq when should either be used?

Thanks,
Kerri.
 
R

Ravikanth[MVP]

Hi


Below are 3 most common ways exceptions are thrown from
within a method.

*1 - If the method that is called throws an exception
which is not caught within that method then caller method
gets the Exception.

*2 - Some operations may also throw exceptions, as shown
above i/j will throw an exception if value of j is 0.

*3 - If in our method code we encounter a condition which
needs to be notified in form of an exception then we can
throw an exception by using throw statement. We create a
new instance of Exception based class and throw it. Later
on we will discover how we can have our own exception
classes and load them with desired information.



HTH
Ravikanth[MVP]
 
K

Kevin Spencer

"Exception" is a type. "New Exception()" is an instance of a class (type).
It's the difference between, for example, saying "Throw Integer" versus
"Throw 6." One is a type, and defines the characteristics of any instance of
that type. The other is an actual instance of a type.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top