I have recently started coding in VB.Net and started using the Try-Catch style of exception handling available in .Net, which I admit is very similar to the exception handling of C++, so it is not all that unfamiliar. In my VB6 code, which I have been using up till now to support a nearly-decade old legacy application, I would often use a fairly consistant error handling block.
Function Sample(intValue As Integer) As Integer On Error Goto Error_Sample ' Do whatever is needed for main operation. Exit_Sample: Exit Function Error_Sample: With Err Select Case .Number ' Specific cases could be put here to handle specific errors. Case 6 ' Division by 0 error intResult = -1 Resume Next Case Else Select Case MsgBox("Error " & .Number & " in " & .Source & vbCr & .Description, _ vbAbortRetryIgnore Or vbDefaultButton2 Or vbIconExclamation, "Form.Sample") Case vbAbort Resume Exit_Sample Case vbRetry Resume Case vbIgnore Resume Next End Select End Select End With End Function
If you have an error that I did not define a handler for, then it falls through to a general handler that displays the error to the user and asks the user what to do - Abort (exit routine), Retry (go back to the statement that generated the error) or Ignore the error (move on to the next statement). Is similar functionalty available using the Try-Catch schema? Abort seems easy (
Exit Function); Resume Next looks like it could be done by just falling through to the next statement after the Try block. Is the functionality of Resume available, or do I have to write it in a loop?