tags:

views:

35

answers:

1

I'm currently maintaining a legacy Visual Basic project that has these "procErr:" statements all over the place. My guess is, that they are used as a way to handle if any error occurred while executing the function, is this correct?

I've converted the project to VB.NET. Would a better way not be, instead of using this procErr syntax, to wrap it inside a Try Catch instead?

+1  A: 

My VB is a bit rusty, but I believe 'ProcErr' is not a reserved keyword. It is just a naming convention in VB to indicate the block that should be executed when an error occurs in your method (or 'procedure', hence the name).

In the actual code, you then have statements like On Error GoTo ProcErr and then you define the procerr block:

procErr:
msgbox "an error has happened"

You could replace this with any other name. In VB.NET you would indeed replace this with a try catch routine:

Try
// code
Catch x As Type
// exceoption handling
Finally
End Try 'cleanup code
Razzie
Razzie: +1 Good answer, however if I may add . . . Exception handling with Try Catch channels our error handling code into a distinct pattern. Be aware that "VB On Error goto" has no such pattern. The error handler can can elect to GOTO any position in the method, and generally there is nothing stopping the coder from adding logic that looks perfectly reasonable in VB3-6, but that would be vomit inducing in Vb.Net. You need to treat each On Error Goto on a case by case basis. Converting legacy VB to VB.Net isn't a straightforward proposition. Best of luck Props :)
Binary Worrier
@Binary: You're right of course. You can't just convert any VB error routine to a simple try-catch since they can differ very much in flow / structure. So you need to examine each one on a case by case basis, yes. That being said, I do think that if possible, you should use the default try-catch routine as much as you can when converting to VB.NET. On the other hand, converting every On Error Resume Next into a try {} catch() {} without actual exception handling isn't very pretty either :-)
Razzie