我想從文件中讀取,如果失敗,請讓用戶重試或以其他方式放棄。到目前爲止,代碼如下所示:如何使用Try和Catch重試VB.Net中的操作?
Read_Again:
Try
my_stream.Read(buffer, 0, read_len)
Catch ex As System.IO.IOException
If MessageBox.Show("try again?") = DialogResult.Retry Then
GoTo Read_Again
Else
Application.Exit() 'just abort, doesn't matter
End If
End Try
我不喜歡Goto,它很醜。但我不知道如何製作一個跨越嘗試和捕捉的循環。
有沒有更好的方法來寫這個?
+1主要是爲了擺脫goto的野心。 :) – Guffa