Visual Basic 6 如何使用异常?
Visual Basic 6 How to use Exceptions?
我在 Internet 上到处寻找解决 VB6 中异常处理的答案,但找不到任何有用的东西。我想向用户显示错误并在遇到该错误时停止执行程序,我不想继续执行。
我研究过使用 End
但这不是我要找的。 End
关闭所有表单并退出。我也用过 Stop
但那个临时暂停执行。
我希望尽可能使用此版本的 Visual Basic 处理逻辑异常。如果没有异常,有没有办法模拟它们?
这是我在所有项目中使用的模板:
Private Sub Test()
On Error GoTo catch
'your code which may cause an error
'if you wanted to raise a user-defined error which start at 513
Err.Raise vbObjectError + 513, "MyModule", "MyMessage"
finally:
'any code that always has to happen
Exit Sub
catch:
'logging, message boxes, etc, however you want to handle the error
MsgBox Err.Number & ": " & Err.Description
Resume finally
End Sub
我在 Internet 上到处寻找解决 VB6 中异常处理的答案,但找不到任何有用的东西。我想向用户显示错误并在遇到该错误时停止执行程序,我不想继续执行。
我研究过使用 End
但这不是我要找的。 End
关闭所有表单并退出。我也用过 Stop
但那个临时暂停执行。
我希望尽可能使用此版本的 Visual Basic 处理逻辑异常。如果没有异常,有没有办法模拟它们?
这是我在所有项目中使用的模板:
Private Sub Test()
On Error GoTo catch
'your code which may cause an error
'if you wanted to raise a user-defined error which start at 513
Err.Raise vbObjectError + 513, "MyModule", "MyMessage"
finally:
'any code that always has to happen
Exit Sub
catch:
'logging, message boxes, etc, however you want to handle the error
MsgBox Err.Number & ": " & Err.Description
Resume finally
End Sub