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
Re: Error handling in components called from ASP
Another suggestion is to reference ASP and response.write your errors to the
browser. I have a similiar problem and am looking for good solution.
-Dave
"James Barbetti" <james_barbetti@yahoo.com> wrote:
>
>>>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
Re: Error handling in components called from ASP
The answer depends on who needs to see the error message. Usually the
clients do *not* need to see the error message itself, all they need to see
is an error page stating that the resource they requested is not available.
IIS 5 lets you redirect specific errors to a custom page--you don't have to
use IIS's default error pages. That way, you can display an informative and
attractive message to users, and then store the "real" error message so
administrators can find out what happened. Here are some options. Write the
error information to:
* the NT Event log -- see the Response.AppendToLog method.
* an email message sent to an administrator -- see the topic CDONTS to
generate the mail message. You'll want some way to avoid sending too many
error messages if you select this method.
* a log file of your choosing -- see the FileSystemObject and the TextStream
object.
* a database table -- in conjunction with secured ASP-based administrative
pages to view, sort, and delete the errors, you have a way for
administrators to track what's happening in the application.
Finally, combining these approaches can be extremely powerful. For example,
you might want to log errors to a database and also trigger an email message
to an administrator if the number of errors in a specified period exceeds
some threshold.
HTH,
Russell Jones
Sr. Web Development Editor
DevX.com
"David" <dstrommer@hotmail.com> wrote in message
news:3be7eead$1@147.208.176.211...
>
> Another suggestion is to reference ASP and response.write your errors to
the
> browser. I have a similiar problem and am looking for good solution.
>
> -Dave
>
>
> "James Barbetti" <james_barbetti@yahoo.com> wrote:
> >
> >>>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
>