Try Catch Finallyが使える

例外処理は [vbnet]Dim sr As System.IO.StreamReader On Error Resume Next sr = System.IO.File.OpenText("redme.txt") If Err.Number<>0 Then MsgBox("エラー番号=" & Err.Number & vbcr & Err.Description, _ MsgBoxStyle.Exclamation) Else sr.close() End If sr = Nothing[/vbnet] でしたが、構造化例外処理が使えます。 [vbnet]Dim sr As System.IO.StreamReader Try sr = System.IO.File.OpenText("a.txt") Catch exp As System.Security.SecurityException MsgBox("アクセス権なし") Catch exp As System.ArgumentException MsgBox("パス名が不正") Finally sr.close() End Try sr = Nothing[/vbnet] DLL内部で発生したエラーの検出 [vbnet]Dim returnCode As Integer returnCode = ShellExecute(Me.Handle, "open", "readme.txt", vbNullString, ApplicationExecutablePath, _ SW_SHOWNORMAL) IF returnCode < = 32 Then Debug.WriteLine("Last DLL Error =" & Err.LastDllError) Debug.WriteLine("Return Value = " & returnCode) End If[/vbnet] エラーを起こすときは [vbnet]Err.Raise(エラー番号*他にも引数がある。)[/vbnet]