Debugging DLLs - best practice

  • Thread starter Thread starter tedqn
  • Start date Start date
T

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?
 
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.
 
Back
Top