Results 1 to 3 of 3

Thread: GetBaseException and InnerException

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    GetBaseException and InnerException

    In my Global.asax file, I'm working with the exceptions like this:

    VB Code:
    1. Dim context As System.Web.HttpContext = HttpContext.Current
    2.         Dim ex As System.Exception = context.Server.GetLastError.GetBaseException()

    Now the question is very simple:

    What is the difference between GetBaseException() and InnerException, and which one should I be working with?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: GetBaseException and InnerException

    BaseException
    ---throws
    ------someOtherException
    ------someOtherException.innerException = (baseException)


    Basically, the baseexception is the exception that caused all the other exceptions to occur. If the a filenotfoundException occurs, and then throws a someOtherException... the innerException of the someOtherException will return the baseexception.

    Which seems rather silly, until you realize there could be many exceptions thrown because of one underlying exception (which is normal).

    So if you had one exception that caused 15 other exceptions to occur (bubble), the 15th exception would have to call the innerException property to get a reference to the 14th exception, which would then have to call its innerException property to get a reference to the 13th exception...so forth. As you see, this would be real pain to tranverse anytime you wanted the underlying base exception of them all... which is why the class has the GetBaseException() method that transverses those layers for you to retrieve the underlying 1st exception that started it all.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: GetBaseException and InnerException

    Excellent explanation, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width