Throw Exception Vs Throw New Exception

Discussion in 'ASP .Net' started by Kerri, Oct 27, 2003.

  1. Kerri

    Kerri Guest

    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.
    Kerri, Oct 27, 2003
    #1
    1. Advertising

  2. 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]


    >-----Original Message-----
    >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.
    >.
    >
    Ravikanth[MVP], Oct 27, 2003
    #2
    1. Advertising

  3. "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.

    "Kerri" <> wrote in message
    news:06ca01c39c79$afab4980$...
    > 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.
    Kevin Spencer, Oct 27, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    2
    Views:
    5,518
    Christophe Vanfleteren
    Jul 1, 2004
  2. Replies:
    15
    Views:
    7,495
    Roedy Green
    Sep 8, 2005
  3. Pao
    Replies:
    12
    Views:
    1,163
    Juan T. Llibre
    Apr 4, 2007
  4. H.S.
    Replies:
    6
    Views:
    538
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    312
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page