Good error-handling strategies

Results 1 to 2 of 2

Thread: Good error-handling strategies

  1. #1
    Christiaan Guest

    Default Good error-handling strategies

    What is a good way to deal with errors in a COM-object? Or are there any (really) good in-depth articles i should know of?<BR><BR>

  2. #2
    SPG Guest

    Default RE: Good error-handling strategies

    Well, I&#039d love to hear about nice articles too, as my method breaks down when getting to really OO code. However, as you may benefit from it, here it is (for Visual Basic):<BR><BR>private property let errorList(byVal strIn as string)<BR> strLastError = "&#060;p class=error&#062;" & strIn & "&#060;/p&#062;" & vbCrLf & db.lastError & strLastError<BR>end property <BR><BR>That gives me anything I tell it, as well as whatever it reported from my generic database handling component. Of course there&#039s a public get version which I print at regular times while testing, and a public clearError subroutine to reset the strLastError value.<BR><BR>Use:<BR>public sub foo(byVal strIn as string)<BR> on error goto ErrorCode<BR> ...<BR>exit sub<BR>errorCode:<BR> lastError = "Error in foo(""" & strIn & """): " & err.description<BR>end sub<BR><BR>And this also lets you put in oops handlers if an error gets thrown, or pick up additional variable state information to help you figure out why the error was being thrown.<BR><BR>Note that you may want to add an "errorCode: strLastError = "Error in Error Handler"" handler line to the error reporter -- sometimes it can go off the deep end if it gets a really unusual error.<BR><BR>Hope it helps. And, of course, if it makes you rich, you should share with me. ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts