创建自定义异常并抛出
你可以创建自定义异常并在执行函数期间抛出它们。作为一般做法,只有在函数无法实现其定义的功能时才应抛出异常。
Private Function OpenDatabase(Byval Server as String, Byval User as String, Byval Pwd as String)
if Server.trim="" then
Throw new Exception("Server Name cannot be blank")
elseif User.trim ="" then
Throw new Exception("User name cannot be blank")
elseif Pwd.trim="" then
Throw new Exception("Password cannot be blank")
endif
'Here add codes for connecting to the server
End function