Exception Handling.

Discussion in 'ASP .Net' started by Rajeev Soni, Jul 18, 2003.

  1. Rajeev Soni

    Rajeev Soni Guest

    Hi,

    Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is the best thing to do:

    1. Dont catch the exception in DAL and let it prop up to the Application level and the Global.Application_Error event log it to any source and show let ASP.NET show custom error page provided in Web.Config file.

    OR

    2. Catch Exception in DAL, Log the error using some Exception Handling mechanism and Tranfer the control to another page using Server.Transfer("ErrorPage.aspx");

    Which one of the above 1 or 2 is the best way to handle exceptions?

    Regards
    Rajeev Soni
     
    Rajeev Soni, Jul 18, 2003
    #1
    1. Advertising

  2. Rajeev Soni

    Rajeev Soni Guest

    Hi,
    Well i had a issue
    1. Do i require to show Exception message to user
    OR
    2. Just to show same static Error message for any kind of errors

    i thought there is no need for me to show the actual message to user, so i only required to log the error in some place before showing the custom static error page to user.

    And here is what i did:
    1. In the Global.asax.cs :
    protected void Application_Error(Object sender, EventArgs e)
    {
    ExceptionManagement objEM = new ExceptionManagement();
    objEM.HandleException();
    }

    2. And in ExceptionManagement class:
    public void HandleException()
    {
    LogException();
    if (SendMail)
    MailException();
    }

    Is is right to use Global.Application_Error event to log errors
    OR
    Use try/catch where ever exception can occur?

    Thanks and regards
    Rajeev

    "Wim Hollebrandse" <wimATwimdows.com> wrote in message news:...
    > 5 tier architecture?! That sounds like too many layers for a start.
    >
    > Of course - you could decide to only catch it at UI level.
    >
    > Whilst that does result in less Exceptions it will make things harder for
    > you to trace and debug certain errors. Hence my recommendation to use custom
    > Exception classes and re-throwing your custom exceptions.
    >
    > Cheers,
    > Wim Hollebrandse
    > http://www.wimdows.com
    > http://www.wimdows.net
    >
    >
    > "Rajeev Soni" <> wrote in message
    > news:...
    > Hi
    >
    > w.r.t.
    > http://msdn.microsoft.com/netframew...ibrary/en-us/dndotnet/html/dotnetperftips.asp
    > "Performance Tips and Tricks in .NET Applications" it says
    >
    > <SNIP>
    > Throw Fewer Exceptions
    > Throwing exceptions can be very expensive, so make sure that you don't throw
    > a lot of them. Use Perfmon to see how many exceptions your application is
    > throwing. It may surprise you to find that certain areas of your application
    > throw more exceptions than you expected. For better granularity, you can
    > also check the exception number programmatically by using Performance
    > Counters
    > </SNIP>
    >
    > So at each place where i interact with DB i need to have Try Catch that in
    > turn will increase the code size. and more over catching and re-throwing the
    > exception and again catching it in app where DAL is used will be addtional
    > overhead for the application.
    >
    > In the case where we have 5-tier architecture application like
    > PL-BL-DAL-Database helper then the exception at Database helper class caused
    > will be catched thrice and thrown thrice.
    >
    > regards
    > rajeev
    >
    > "Wim Hollebrandse" <wimATwimdows.com> wrote in message
    > news:...
    > > Best practice IMHO is to create your own custom Exception classes, catch

    > the
    > > Exceptions in your DAL, but re-throw your own custom exceptions with more
    > > detailed info as to where the error occurred. They can then be dealt with

    > in
    > > the app which uses the DAL.
    > >
    > > Hope that helps,
    > > Wim Hollebrandse
    > > http://www.wimdows.com
    > > http://www.wimdows.net
    > >
    > >
    > > "Rajeev Soni" <> wrote in message
    > > news:...
    > > Hi,
    > >
    > > Considering the scenario for handling exceptions in Web Application where

    > we
    > > have Presentation layer, Business layer and Data Access layer; if there

    > any
    > > exception is occurred in DAL, what is the best thing to do:
    > >
    > > 1. Dont catch the exception in DAL and let it prop up to the Application
    > > level and the Global.Application_Error event log it to any source and show
    > > let ASP.NET show custom error page provided in Web.Config file.
    > >
    > > OR
    > >
    > > 2. Catch Exception in DAL, Log the error using some Exception Handling
    > > mechanism and Tranfer the control to another page using
    > > Server.Transfer("ErrorPage.aspx");
    > >
    > > Which one of the above 1 or 2 is the best way to handle exceptions?
    > >
    > > Regards
    > > Rajeev Soni
    > >
    > >

    >
    >
     
    Rajeev Soni, Jul 18, 2003
    #2
    1. Advertising

  3. Best practice IMHO is to create your own custom Exception classes, catch the
    Exceptions in your DAL, but re-throw your own custom exceptions with more
    detailed info as to where the error occurred. They can then be dealt with in
    the app which uses the DAL.

    Hope that helps,
    Wim Hollebrandse
    http://www.wimdows.com
    http://www.wimdows.net


    "Rajeev Soni" <> wrote in message
    news:...
    Hi,

    Considering the scenario for handling exceptions in Web Application where we
    have Presentation layer, Business layer and Data Access layer; if there any
    exception is occurred in DAL, what is the best thing to do:

    1. Dont catch the exception in DAL and let it prop up to the Application
    level and the Global.Application_Error event log it to any source and show
    let ASP.NET show custom error page provided in Web.Config file.

    OR

    2. Catch Exception in DAL, Log the error using some Exception Handling
    mechanism and Tranfer the control to another page using
    Server.Transfer("ErrorPage.aspx");

    Which one of the above 1 or 2 is the best way to handle exceptions?

    Regards
    Rajeev Soni
     
    Wim Hollebrandse, Jul 18, 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. Babu
    Replies:
    1
    Views:
    2,929
    Jim Gibson
    Mar 10, 2005
  2. Mark Tarver
    Replies:
    22
    Views:
    1,377
    J Kenneth King
    Apr 26, 2009
  3. Peter
    Replies:
    34
    Views:
    2,018
    James Kanze
    Oct 17, 2009
  4. VSK
    Replies:
    0
    Views:
    267
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    218
    Iñaki Baz Castillo
    Apr 15, 2008
Loading...

Share This Page