Home All Groups Group Topic Archive Search About

Debugging DLLs - best practice

Author
2 May 2006 4:27 AM
tedqn
I'm used to ASP detail error showing line #. Now I've been playing with
DLLs. When the error occurs, it doesn't tell me which line of code
causes it. Is there a way or do I have to do a try..catch on every
possible place that can cause error?

Author
2 May 2006 9:41 AM
Phill W.
te***@yahoo.com wrote:
> I'm used to ASP detail error showing line #. Now I've been playing with
> DLLs. When the error occurs, it doesn't tell me which line of code
> causes it. Is there a way or do I have to do a try..catch on every
> possible place that can cause error?
>
Your DLL should have a way of logging any error, regardless of what the
client ASP may (or may not!) do with any error you send back to it.

Wrap every "exposed" method with a Try..Catch, as in

Public Function foo( ... ) As String ' or whatever

    Try
       Return InternalFoo( ...  )
    Catch ex as Exception
       LogToFile( ex ) ' Save it where we can find it
       Throw ' send error back to client
    End Try

End Function

Private Sub LogToFile( ByVal ex As Exception )
    Try
       Dim sw As New StreamWriter( "file_in_known_location.log" )
       sw.WriteLine( DateTime.Now.ToString() & vbNewLine _
          & ex.ToString )
       ' and anything else that might be useful
       sw.Close()
    Catch ex As Exception
       ' What can you do?
    End Try
End Sub

HTH,
    Phill  W.
Author
2 May 2006 9:57 AM
Patrice
And/or use a global.asax error handler. See :
http://msdn2.microsoft.com/en-us/library/24395wz3.aspx

--
Patrice

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> a écrit dans le message de
news: e379bm$u***@yarrow.open.ac.uk...
Show quoteHide quote
> te***@yahoo.com wrote:
>> I'm used to ASP detail error showing line #. Now I've been playing with
>> DLLs. When the error occurs, it doesn't tell me which line of code
>> causes it. Is there a way or do I have to do a try..catch on every
>> possible place that can cause error?
>>
> Your DLL should have a way of logging any error, regardless of what the
> client ASP may (or may not!) do with any error you send back to it.
>
> Wrap every "exposed" method with a Try..Catch, as in
>
> Public Function foo( ... ) As String ' or whatever
>
>    Try
>       Return InternalFoo( ...  )
>    Catch ex as Exception
>       LogToFile( ex ) ' Save it where we can find it
>       Throw ' send error back to client
>    End Try
>
> End Function
>
> Private Sub LogToFile( ByVal ex As Exception )
>    Try
>       Dim sw As New StreamWriter( "file_in_known_location.log" )
>       sw.WriteLine( DateTime.Now.ToString() & vbNewLine _
>          & ex.ToString )
>       ' and anything else that might be useful
>       sw.Close()
>    Catch ex As Exception
>       ' What can you do?
>    End Try
> End Sub
>
> HTH,
>    Phill  W.