How do I use Try and Catch to retry an operation in VB.Net?

Viewed 13661

I'd like to read from a file and if I fail, let the user retry or otherwise give up. So far the code looks like this:

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

I don't like the Goto, it's ugly. But I don't see how to make a loop that spans the try and catch.

Is there a better way to write this?

3 Answers
Related