Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Handling an exception in Visual Basic?

I have the following happening:

Timer1 is set to at every interval, to use code:

richtextbox.loadfile (file path)

so the rich text box in my program constantly refreshes to say what the file in the path contains, however, for some periods the folder the file is in becomes unavailable for a short moment (due to another program using the folder) and of course this causes the Unhandeled Exception "File Not Found" error to appear.

How do I code the program so when this exception occurs it'll do something for example: textbox1.text = "text here"

or

form2.show

Using VB 2005

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Try

    richtextbox.loadfile(yourfile)

    Catch e as Exception

    richtextbox.AppendText(e.Message)

    End Try

    This will write the error message into your textbox.

    Source(s): VB.NET Programmer
  • Anonymous
    5 years ago

    inner most Sub RTBload_btn_Click(ByVal.... attempt RTB1.LoadFile(your filepath, or var ) capture ex as exception MSGBox("The requested FilePath can't be discovered") go out Sub end attempt end Sub ' this can forestall the kind from preventing at an exception. ' no longer certain if go out Sub is major. attempt with out it first, if the shape loops, then upload it.

Still have questions? Get your answers by asking now.