catching all errors

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Nov 19, 2006.

  1. hey all,
    is there a way to catch all errors for my webform without using the
    global.asax page?
    thanks,
    rodchar
     
    =?Utf-8?B?cm9kY2hhcg==?=, Nov 19, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?cm9kY2hhcg==?=

    Mark Rae Guest

    "rodchar" <> wrote in message
    news:D...

    > is there a way to catch all errors for my webform without using the
    > global.asax page?


    Other than surrounding all your code with try...catch, I don't think so...
     
    Mark Rae, Nov 19, 2006
    #2
    1. Advertising

  3. Hello Mark,

    BTW, u can handle your exceptions with System.Web.UI.Page.Error even

    MR> "rodchar" <> wrote in message
    MR> news:D...
    MR>
    >> is there a way to catch all errors for my webform without using the
    >> global.asax page?
    >>

    MR> Other than surrounding all your code with try...catch, I don't think
    MR> so...
    MR>
    ---
    WBR,
    Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

    "At times one remains faithful to a cause only because its opponents do not
    cease to be insipid." (c) Friedrich Nietzsche
     
    Michael Nemtsev, Nov 19, 2006
    #3
  4. =?Utf-8?B?cm9kY2hhcg==?=

    Annie Guest

    Hi Michael,
    Can you please explain what mean?
    many thanks


    "Michael Nemtsev" <> wrote in message
    news:...
    > Hello Mark,
    >
    > BTW, u can handle your exceptions with System.Web.UI.Page.Error even
    >
    > MR> "rodchar" <> wrote in message
    > MR> news:D...
    > MR>
    >>> is there a way to catch all errors for my webform without using the
    >>> global.asax page?
    >>>

    > MR> Other than surrounding all your code with try...catch, I don't think
    > MR> so...
    > MR> ---
    > WBR,
    > Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour
    >
    > "At times one remains faithful to a cause only because its opponents do
    > not cease to be insipid." (c) Friedrich Nietzsche
    >
    >
     
    Annie, Nov 20, 2006
    #4
  5. =?Utf-8?B?cm9kY2hhcg==?=

    Mark Rae Guest

    "Annie" <> wrote in message
    news:...

    > Can you please explain what mean?


    http://msdn2.microsoft.com/en-us/library/ed577840(VS.80).aspx

    Pay particular attention to the very first line of the article, which says:
    "If possible, you should handle errors in Try/Catch blocks within your
    code..."

    That is the preferred method of error handling in .NET applications, but
    Michael is correctly reminding me that it's not the *ONLY* way...

    AAMOI, is anyone actually using Page_Error...?
     
    Mark Rae, Nov 20, 2006
    #5
  6. =?Utf-8?B?cm9kY2hhcg==?=

    Karl Seguin Guest

    That website is TOTALLY AND ABSOLUTELY WRONG. It _WILL_ get corrected during
    the next major revision (or help me god...). Well over 90% of the time you
    can't handle an actual exception..all you can do is clean up...in which case
    you should be using try/finallys and "usings". Your logging code should be
    centralized, and the best way to do this is with Global.asax's on error ..

    Handling exceptions in global.asax is the CORRECT way to do things.

    As was mentioned, you can also catch errors in the page. you can do this by
    overriding the OnError method.

    protected override void OnError(EventArgs e)
    {
    ...
    }

    if you put this in a base class and have all your pages inherit from it,
    you're good to go.

    More on exception hanlding in .NET:
    http://codebetter.com/blogs/karlseguin/archive/2006/04/05/142355.aspx

    Karl
    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "Mark Rae" <> wrote in message
    news:...
    > "Annie" <> wrote in message
    > news:...
    >
    >> Can you please explain what mean?

    >
    > http://msdn2.microsoft.com/en-us/library/ed577840(VS.80).aspx
    >
    > Pay particular attention to the very first line of the article, which
    > says: "If possible, you should handle errors in Try/Catch blocks within
    > your code..."
    >
    > That is the preferred method of error handling in .NET applications, but
    > Michael is correctly reminding me that it's not the *ONLY* way...
    >
    > AAMOI, is anyone actually using Page_Error...?
    >
     
    Karl Seguin, Nov 20, 2006
    #6
  7. =?Utf-8?B?cm9kY2hhcg==?=

    Mark Rae Guest

    "Karl Seguin" <> wrote in
    message news:...

    > That website is TOTALLY AND ABSOLUTELY WRONG. It _WILL_ get corrected
    > during the next major revision (or help me god...).


    Glad to hear it!

    For the record, I wasn't actually recommending following its contents -
    quite the reverse... :)

    > Well over 90% of the time you can't handle an actual exception..all you
    > can do is clean up...
    > in which case you should be using try/finallys and "usings".


    I couldn't agree more...

    >Your logging code should be centralized, and the best way to do this is
    >with Global.asax's on error ..


    Again, totally agreed...
     
    Mark Rae, Nov 20, 2006
    #7
    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. Mikael Engdahl

    Catching ASP.NET errors

    Mikael Engdahl, Aug 15, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,386
    S. Justin Gengo
    Aug 15, 2003
  2. TonyG

    Catching Framework Errors

    TonyG, Aug 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    327
    MS News \(MS ILM\)
    Aug 26, 2003
  3. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    986
    Mark Goldin
    Jan 17, 2004
  4. darrel
    Replies:
    0
    Views:
    321
    darrel
    Sep 28, 2005
  5. yawnmoth
    Replies:
    97
    Views:
    4,760
    Bent C Dalager
    Feb 27, 2009
Loading...

Share This Page