locked
Exception handling in multi-tiered applications? RRS feed

  • Question

  • User48651432 posted

    Even though I'm trying to implement exception handling in a multi-tiered Windows application, catching and throwing exceptions should be the same for Windows and Web (sans global.asax and web.config custom errors).

    I have a webform with a texbox that displays exceptions. So my webform invokes a method in BusinessTier class which then invokes a method in DataTier class. How can I throw my DataTier method exception so it reaches my webform?

    Thanks.

    Tuesday, April 27, 2010 1:25 PM

Answers

  • User-952121411 posted

    How can I throw my DataTier method exception so it reaches my webform?
     

    One mis conception is that exceptions will not bubble up unless explicitly thrown; this is not true.  Your generated exception should and will automatically bubble up From the DataTier -> to the BusinessTier -> to the webform (UI) unless handled and consumed beforehand.  No 'Throw()' statements are needed, and in fact they will disrupt the StackTrace if improperly used.

    Try it out: generate or cause an exception at your lowest layer, and place only a 'Catch' at your highest layer (UI) with a break point set up.  Sure enough the exception will bubble all the way back up automatically. Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 27, 2010 4:26 PM

All replies

  • User-1659704165 posted

    Hi,

    u can use "ApplicationException"

    http://msdn.microsoft.com/en-us/library/aa479319.aspx

    chk the above link for more info


    Tuesday, April 27, 2010 2:15 PM
  • User-952121411 posted

    How can I throw my DataTier method exception so it reaches my webform?
     

    One mis conception is that exceptions will not bubble up unless explicitly thrown; this is not true.  Your generated exception should and will automatically bubble up From the DataTier -> to the BusinessTier -> to the webform (UI) unless handled and consumed beforehand.  No 'Throw()' statements are needed, and in fact they will disrupt the StackTrace if improperly used.

    Try it out: generate or cause an exception at your lowest layer, and place only a 'Catch' at your highest layer (UI) with a break point set up.  Sure enough the exception will bubble all the way back up automatically. Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 27, 2010 4:26 PM