« XLS XML Hello World | Main | Outlook New Mail Responder »
October 18, 2002
VB add Error Handling to a class
During a project a couple of years ago, we realized that there were many VB classes that lacked basic error handling clauses. We needed to add them to troubleshoot a problem. Microsoft was helping us out and asked us to add error handling to every method of every class. We had over 500 class files. So we used a perl script like this one (not sure if this is the final version). It worked great. We tested the code changes and checked everything in. The problem ended up being inside MTS and required a hot fix, which ended up in NT 4.0 Service Pack 6a.
# /usr/bin/perl # takes a list of file names from the command line while ($#ARGV >= 0 ){ $fname = pop; open CLSFILEIN, $fname; print $fname . "_tmp"; open CLSFILEOUT, ">".$fname . "_tmp"; print "FILE:",$fname, "\n"; while (){ if (/^Public/){ s/Public/Private/ } if (/^Private[\s]+Property+[\s]+Get[\s]+([\w]+)([\S\s]+$)/) { print "Private P Get \n"; $methodname=$1; print CLSFILEOUT; print CLSFILEOUT "On Error Goto Er\n"; } elsif (/^Private[\s]+Property+[\s]+Let[\s]+([\w]+)([\S\s]+$)/) { print "Private P Let \n"; $methodname=$1; print CLSFILEOUT; print CLSFILEOUT "On Error Goto Er\n"; } elsif (/^Private[\s]+Function[\s]+([\w]+)/) { print "Private Function\n"; $methodname=$1; print CLSFILEOUT; print CLSFILEOUT "On Error Goto Er\n"; } elsif (/^Private[\s]+Sub[\s]+([\w]+)/) { print "Private Sub\n"; $methodname=$1; print CLSFILEOUT; print CLSFILEOUT "On Error Goto Er\n"; # } elsif (/^Private[\s]+[\w]+[\s]+([\w]+)/) { # print "Private \n"; # $methodname=$1; # print CLSFILEOUT; # print CLSFILEOUT "On Error Goto Er\n"; } elsif (/^End Property/) { print "End P \n"; print CLSFILEOUT " Exit Property\n"; print CLSFILEOUT "Er:\n"; print CLSFILEOUT " AfErr Err, App.EXEName, c_sClassName, ",'"', $methodname,'"',", aetError\n"; print CLSFILEOUT "End Property\n" } elsif (/^End Sub/) { print "End S \n"; print CLSFILEOUT " Exit Sub\n"; print CLSFILEOUT "Er:\n"; print CLSFILEOUT " AfErr Err, App.EXEName, c_sClassName, \"", $methodname,"\", aetError\n"; print CLSFILEOUT "End Sub\n"; } elsif (/^End Function/) { print "End F \n"; print CLSFILEOUT " Exit Function\n"; print CLSFILEOUT "Er:\n"; print CLSFILEOUT " AfErr Err, App.EXEName, c_sClassName, \"", $methodname,"\", aetError\n"; print CLSFILEOUT "End Function\n"; } else { print CLSFILEOUT; } } close CLSFILEIN; close CLSFILEOUT; rename $fname, $fname."old"; rename $fname."_tmp",$fname; }
Posted by Chris at October 18, 2002 02:51 PM
Trackback Pings
TrackBack URL for this entry:
http://www.christulino.com/cgi-bin/mt/mt-tb.cgi/29