-1
私のプログラムが「UnHandled Exception」をポップしているとき、私のプログラムのボタンクリックを呼び出すことはできますか?私は実際に '修正'または例外を回避することができるフォームのボタンを持っています。私の思考の一例)未処理の例外のVBでは、ボタンをクリックしてループを再開しますか?
私のプログラムが「UnHandled Exception」をポップしているとき、私のプログラムのボタンクリックを呼び出すことはできますか?私は実際に '修正'または例外を回避することができるフォームのボタンを持っています。私の思考の一例)未処理の例外のVBでは、ボタンをクリックしてループを再開しますか?
アプリケーションイベントを有効にしてそこから処理します。未処理の例外機能を使用してフォームを表示することができます。下記のコードをご覧ください。
Imports System.Text
Imports System.IO
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
'One of the global exceptions we are catching is not thread safe,
'so we need to make it thread safe first.
Private Delegate Sub SafeApplicationThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
'There are three places to catch all global unhandled exceptions:
'AppDomain.CurrentDomain.UnhandledException event.
'System.Windows.Forms.Application.ThreadException event.
'MyApplication.UnhandledException event.
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException
AddHandler System.Windows.Forms.Application.ThreadException, AddressOf app_ThreadException
' AddHandler AccessViolationException, AddressOf app_AccessViolationException
End Sub
'Private Sub app_AccessViolationException(ByVal sender As Object, ByVal ex As System.AccessViolationException)
'End Sub
Private Sub app_ThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
'This is not thread safe, so make it thread safe.
If MainForm.InvokeRequired Then
' Invoke back to the main thread
MainForm.Invoke(New SafeApplicationThreadException(AddressOf app_ThreadException), _
New Object() {sender, e})
Else
frmDebug.Show()
End If
End Sub
Private Sub AppDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
frmDebug.Show()
End Sub
Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
frmDebug.Show()
End Sub
End Class
End Namespace
質問は不明です。どのコード、どのボタン、何のループ?コードを[try/catchブロック]に置くだけです(https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-最終的なステートメント)。これは、ドキュメンテーションとすべてのVB.NETチュートリアルで十分にカバーされています。 Googleでは '.NET例外処理 'を行っています。 –
私の投稿を編集したばかりなので、もっと明白になるかもしれません。 – Shlomi
例外があるときに何かしたいのであれば、その例外を処理する必要があります。これを行うには、Try/Catchブロックを使用します。 – Blackwood