Where do we output exception messages from App_Code\MyClass.cs?

Discussion in 'ASP .Net' started by gnewsgroup, Sep 21, 2007.

  1. gnewsgroup

    gnewsgroup Guest

    In a web application, we do not have access to the Console.

    And quite often, in order to share a class across the entire web
    application, we put it under App_Code.

    Normally, classes placed under App_Code do not inherit
    System.Web.UI.Page, and therefore do not have access to Response.Write
    or any of our Web controls.

    Nor do we have a console.

    So, here is my question: How do we handle exceptions thrown from, for
    example, App_Code\MyClass.cs ?

    Should we say something like below?

    try
    {
    // blah blah
    }
    catch(SqlException se)
    {
    throw new Exception(se.Message);
    }

    Thank you!
    gnewsgroup, Sep 21, 2007
    #1
    1. Advertising

  2. Re-throwing Exceptions is more expensive (on the performance of the
    application) than letting the exception to propagate automatically. So if
    your class App_Code\MyClass.cs does not do anything with a caught exception,
    remove the try ... catch block from it and let the web page to handle it.

    You might find this article helpful:
    http://msdn2.microsoft.com/en-us/library/ms954599.aspx#emag__exception_propagation
    --
    Regards,

    Phillip Williams (MCPD Web Developer)
    http://mcts-study-practices.com/
    http://www.webswapp.com


    "gnewsgroup" wrote:

    > In a web application, we do not have access to the Console.
    >
    > And quite often, in order to share a class across the entire web
    > application, we put it under App_Code.
    >
    > Normally, classes placed under App_Code do not inherit
    > System.Web.UI.Page, and therefore do not have access to Response.Write
    > or any of our Web controls.
    >
    > Nor do we have a console.
    >
    > So, here is my question: How do we handle exceptions thrown from, for
    > example, App_Code\MyClass.cs ?
    >
    > Should we say something like below?
    >
    > try
    > {
    > // blah blah
    > }
    > catch(SqlException se)
    > {
    > throw new Exception(se.Message);
    > }
    >
    > Thank you!
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Sep 21, 2007
    #2
    1. Advertising

  3. gnewsgroup

    gnewsgroup Guest

    On Sep 21, 3:44 pm, Phillip Williams <>
    wrote:
    > Re-throwing Exceptions is more expensive (on the performance of the
    > application) than letting the exception to propagate automatically. So if
    > your class App_Code\MyClass.cs does not do anything with a caught exception,
    > remove the try ... catch block from it and let the web page to handle it.
    >
    > You might find this article helpful: http://msdn2.microsoft.com/en-us/library/ms954599.aspx#emag__exceptio...
    > --
    > Regards,
    >
    > Phillip Williams (MCPD Web Developer)http://mcts-study-practices.com/http://www.webswapp.com
    >
    > "gnewsgroup" wrote:
    > > In a web application, we do not have access to the Console.

    >
    > > And quite often, in order to share a class across the entire web
    > > application, we put it under App_Code.

    >
    > > Normally, classes placed under App_Code do not inherit
    > > System.Web.UI.Page, and therefore do not have access to Response.Write
    > > or any of our Web controls.

    >
    > > Nor do we have a console.

    >
    > > So, here is my question: How do we handle exceptions thrown from, for
    > > example, App_Code\MyClass.cs ?

    >
    > > Should we say something like below?

    >
    > > try
    > > {
    > > // blah blah
    > > }
    > > catch(SqlException se)
    > > {
    > > throw new Exception(se.Message);
    > > }

    >
    > > Thank you!


    OK, thank you very much. I haven't been a good exception catcher.
    But your idea helps clarify a major exception principle. Thank you.
    gnewsgroup, Sep 22, 2007
    #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. Mario Fratelli
    Replies:
    32
    Views:
    1,375
    Phlip
    Dec 9, 2003
  2. Dave
    Replies:
    1
    Views:
    350
    Ron Natalie
    Dec 8, 2003
  3. modemer
    Replies:
    11
    Views:
    638
    modemer
    Mar 21, 2005
  4. Gunnar G
    Replies:
    5
    Views:
    374
    Howard
    Jul 8, 2005
  5. tom
    Replies:
    5
    Views:
    408
Loading...

Share This Page