Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Exception Handling.

    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 Guest

  2. Similar Questions and Discussions

    1. PHP5 and exception handling
      Hello, I'm used to exception handling in C++ or Delphi/Object Pascal and I had lotsa expectations for PHP5 exception handling, especially since I...
    2. Handling error with exception
      Do perl have handling error (exception) mechanism? for example: java use : try{...} catch{...} Thanks
    3. Exception handling question
      Hi there, I have an ASP.NET web site and service. The site calls methods from the web-service. Whenever a service call throws an exception, I'd...
    4. PHP, MySQL and exception handling
      I want to find out how I can ensure that if MySql has a burp and can't write to my DB, I will have a way of capturing the error and show my users...
    5. SoapExtension for Global Exception handling; but prevent exception from propagating!!
      Hi, I wrote a SoapExtension for Global Exception handling in Webservice and it works!!!! Now i want to catch the exception that happen in the...
  3. #2

    Default Re: Exception Handling.

    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:Oi8UTySTDHA.2276@TK2MSFTNGP10.phx.gbl...
    > 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
    > [url]http://www.wimdows.com[/url]
    > [url]http://www.wimdows.net[/url]
    >
    >
    > "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message
    > news:O5FiGORTDHA.1288@tk2msftngp13.phx.gbl...
    > Hi
    >
    > w.r.t.
    > [url]http://msdn.microsoft.com/netframework/using/Understanding/perf/default.aspx?pull=/library/en-us/dndotnet/html/dotnetperftips.asp[/url]
    > "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:OajPIGRTDHA.2092@TK2MSFTNGP10.phx.gbl...
    > > 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
    > > [url]http://www.wimdows.com[/url]
    > > [url]http://www.wimdows.net[/url]
    > >
    > >
    > > "Rajeev Soni" <rajeev_s@dev.vsofti.stph.net> wrote in message
    > > news:eFdLHxQTDHA.2480@tk2msftngp13.phx.gbl...
    > > 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 Guest

  4. #3

    Default Re: Exception Handling.

    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
    [url]http://www.wimdows.com[/url]
    [url]http://www.wimdows.net[/url]


    "Rajeev Soni" <rajeev_s@dev.vsofti.stph.net> wrote in message
    news:eFdLHxQTDHA.2480@tk2msftngp13.phx.gbl...
    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 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139