Throw Exception Vs Throw New Exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kerri

    Throw Exception Vs Throw New Exception

    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]

    #2
    Throw Exception Vs Throw New Exception

    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]

    [color=blue]
    >-----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.
    >.
    >[/color]

    Comment

    • Kevin Spencer

      #3
      Re: Throw Exception Vs Throw New Exception

      "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

      Big Things are made up of
      Lots of Little Things.

      "Kerri" <anonymous@disc ussions.microso ft.com> wrote in message
      news:06ca01c39c 79$afab4980$a10 1280a@phx.gbl.. .[color=blue]
      > 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.[/color]


      Comment

      Working...