Things That Don't Belong

Somewhere, somehow I don't think it was thought through very well

Earth Date 2008.07.21

Posted by Rich Wheadon | Permalink




Someone walked up to me giggling and showed me his brand new iPod… it took a couple seconds for me to recognize what was on his screen… a picture of an egg in a toaster oven. As I gazed at the picture and attempted to fathom the reasoning behind an egg in a toaster oven I was hit with a second wave of puzzlement. You see it wasn’t just any toaster oven, but the one 50 feet away from me in the office kitchen, I gasped and mumbled “I don’t think this is going to be good.” I immediately brought up FireFox and googled “egg in the toaster oven” and found what I expected about 3 results down the list… “Exploding Egg in a Toaster Oven” compliments of UTube.



Without pause I dashed to the kitchen and found one of the ladies in the office waiting for her egg to finish. I squinted at the egg and then casually offered “You know those things blow up when you bake them, right?” Her nervous fumbling to turn off the toaster oven and quiet prayers for the egg to not blow up were quite humorous. As I walked away from the kitchen, laughing on the inside, I realized that poor Nancy’s egg episode is not entirely unlike the stuff we do in other areas of life that could end up blowing up. As I went back to my desk it only took a second to find something else that didn’t belong, an error handler that reads like this:



....  
endInit:
Exit Sub
HandleError:
'Write the current error to the agent log.
errMsg = "Line " + Cstr\(Erl\) + " of 'Initialize' \(" + Cstr\(Err\) + "\): " + Error$
Call agentLog.LogError\(agentLog.Numerrors, errMsg\)
If Not curDoc Is Nothing Then
Call agentLog.LogAction\("\[Processing doc with UNID = " + curDoc.UniversalID + "\]"\)
End If
If Erl > 117 And Erl < 156 Then
transType(0) = "Unknown"
transType(1) = ""
Resume endTransType
Elseif Erl > 164 And Erl < 230 Then
Resume endSendTrans
Elseif Erl > 230 And Erl < 263 Then
Resume endStats
Elseif Erl > 112 And Erl < 271 Then
Resume nextDoc
Elseif Erl > 79 And Erl < 283 Then
Resume endAllDocs
Else
Resume endInit
End If

End Sub


Thank you very much Dr. Dufus for making me reprogram the error handler every time i have to add/subtract lines from the overall subroutine. If you are reading this and you write code like that cited above then please consider yourself smacked. Although I would have liked to overhaul the entire piece of twisted logic that led up to the error handler here, I simply added a variable to the sub called “zone” then I sectioned the code into zones that represented the line counters and replaced the numbers with those zones:



HandleError:
'Write the current error to the agent log.
errMsg = "Line " + Cstr(Erl) + " of 'Initialize' (" + Cstr(Err) + "): " + Error$
Call agentLog.LogError(agentLog.Numerrors, errMsg)
If Not curDoc Is Nothing Then
Call agentLog.LogAction("[Processing doc with UNID = " + curDoc.UniversalID + "]")
end if
If zone="HandleTransType" Then
transType(0) = "Unknown"
transType(1) = ""
Resume endTransType
Elseif zone = "HandleTransSend" Then
Resume endSendTrans
Elseif zone="HandleStats" Then
Resume endStats
Elseif zone="HandleDoc" Then
Resume nextDoc
Elseif zone = "HandleCollection" Then
Resume endAllDocs
Else
exit sub
End If

End Sub


Now the error handler can handle line changes. In reality the code in each zone probably should have gone into functions that returned something for its respective chunk, whatever.
There you go, Eggs to Error Handlers.
rich