|
-
Re: Error handling in components called from ASP
>>Matt asked:
>>I am writing a component to update a recordset, but I am not sure where
>>should I write the error handling. If i write th error handling in
>>the Component,how can I call this in the ASP. Thanks.
>Craig said:
>You should write the error handler in the component and then use the Raise
>method of the Err object to raise that error or some kind of error message
>back to the ASP code. You can then display the error message in your ASP
>code.
Yes, and it should work. But it doesn't. Error messages don't survive
across the component/ASP boundary. Even error numbers are lost.
So:
1. Handle errors in *both* the component and the ASP code.
(The correct answer to "where do I handle an error" is always:
everywhere).
2. Don't just do Err.Raise to notify the caller of an error, in your
component. Cache the error number and error message in
properties of your COM component, first.
Like so (in a VB COM component) (in your error trap block):
mErrorNumber = Err.Number
mErrorDesc = Err.Description
mErrorSource = Err.Source
'*before* doing the Err.Raise.
3.Then in your ASP, if you
detect an error, you query that information via properties.
For example, in a VB component
Public Property LastErrorNumber() AS Long
LastErrorNumber = mErrorNumber
End Property
Alternatively, you could suppress the error in the component and return
a result code (say, True for success, False for failure). The problem with
this approach is that if you forget to put error-handling in the calling
ASP
it will seem to have worked even when it hasn't. So raising an error is
probably better.
Good luck with your component!
-James
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks