- Are there any exceptions though?
- Where the usage is permitted?
- If not show how that code should rewritten as.
I give the first suggestion.
How to do a retry?, when the exception is catched.
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim myFile = openFileDialog1.FileName
Dim retrys = 0
Try
Using objReader = New StreamReader(myFile)
Try
While Not objReader.EndOfStream
JumpBackIn:
Dim str = objReader.ReadLine.Split("/"c)
' output to rich text box
RTBUnformatedData.Text &= String.Format("{0} {1} {2}", str(1), str(4), str(5)) & vbNewLine
End While
Catch ex_OutOfMem As OutOfMemoryException When retrys > 0
' Try again upto 3 times.
If retrys < 3 Then
objReader.DiscardBufferedData()
retrys += 1
' Jump back to before read.
GoTo JumpBackIn
Else
' otherwise throw the exception
Throw ex_OutOfMem
End If
Catch ex_OutOfMem As OutOfMemoryException
' Discard data and try again
objReader.DiscardBufferedData()
retrys = 1
GoTo JumpBackIn
Catch ex_IO As IOException
Throw ex_IO
Catch ex As Exception
Throw ex
Finally
objReader.Close()
End Try
End Using
Catch Ex As Exception
MessageBox.Show("Cannot read file " & Ex.Message.ToString)
End Try
End If
Do you have a piece of code that demonstrates acceptable usage of GOTO? If so post it.
This post has been edited by AdamSpeight2008: 06 September 2011 - 09:56 AM

New Topic/Question
Reply



MultiQuote





|