Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 9th, 2003, 03:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default throwing exceptions...!?

How is it with these exceptions!?

In some setup a function D throws an exception, and D is called by C, and C is called by B, and B is called by A. Is it then enough to try/catch the exception in A, or should the exception be caught in each one of the functions C, B and A...!?

Thanks in advance.

Jacob.
__________________
Danish audio books for download at http://www.lytenbog.dk (Danske lydbøger til download).
  #2 (permalink)  
Old October 9th, 2003, 03:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I think I figured it out myself !

It is enough to do it in A, but the reasson why I asked was because it couldn't be... I thought! But I think the problem is different.

My exception is not caught because it happens when an event method is carried out, and this is probably before anything else happens or something like this...!?

Jacob.
  #3 (permalink)  
Old October 9th, 2003, 03:19 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You COULD catch it in any of those places. Keep in mind that if something in D fails and you catch it, handle it then continue, everything will continue on happily thru the rest of the execution of C,B and A. So.. you need to make sure that you have some means of notifying calling functions in the event you catch a handlable exception.

Here is what I do for these sorts of things...

I have created a virtual class called BaseReturnArgs. It contains a boolean property "Success", a string property "ErrorMessage" and a System.Exception property "Exception". Then for whatever I'm doing (lets say I'm writing a data controller that returns a DataTable), I create a class that is derived from BaseReturnArgs, and I call it MyDataReturnArgs where "MyData" is something more meaningfull, like "GetUsers" etc. Then my function returns my customized return args object. So can then call my methods and get back that object, check to see if it succeeded, then do what I want with either the ErrorMessage or the inner exception.

The advantage to this is that I can handle things differently based on what is returned in that object: If InnerException is Nothing/null then I can check the ErrorMessage. This gives me the ability to use a "Fail" state for expected errors ("User doesn't exist", "Bad login", etc.).

Peter
  #4 (permalink)  
Old October 9th, 2003, 03:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, thats a pretty good idea, though it took me several read-throughs in order to get the concept!

Thanks again

Jacob.


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectSingleNode throwing exception: anup_daware .NET Framework 2.0 1 February 3rd, 2008 12:04 PM
Axis client throwing exception sometimes chandootechie J2EE 0 March 17th, 2006 07:51 AM
RangeValidaor throwing exception anup_daware .NET Framework 1.x 0 March 16th, 2006 07:54 AM
beanutils.describe throwing InvocationTargetExcept a007spy J2EE 0 September 22nd, 2004 04:31 PM
Error catching and throwing - code rjp Access VBA 1 August 25th, 2004 08:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.