• 0

[vb .net] Handling FileNotFoundException


Question

8 answers to this question

Recommended Posts

  • 0

thanx, I'm not really making my own classes but in my program, the program has to read alot of files and instead of crashing I would prefer to send out an error message describing the issue to help myself deal with supporting the software.

  • 0
  bangbang023 said:
thanx, I'm not really making my own classes but in my program, the program has to read alot of files and instead of crashing I would prefer to send out an error message describing the issue to help myself deal with supporting the software.

if you have no classes you have no application. :blink:

You also have an ACCESS DENIED BUG you need to address. Let me tell you this now, your DNote App doesn't work in a Domain Environment at all. To view this change your permissions from ADMINSTRATOR to USER and then your application will crash like a mofo.

  • 0
  devgrp said:
Try this

Try
	File.Open("myfile.txttch ex As FileNotFoundException
	lblMessage.Text = "File not found"
End Try

thanx I finally found my answer in MSDN thought. Your code wasn't 100% correct.

  Quote
Try

            FileOpen(1, skinChoice & "\readme.txt", OpenMode.Input)

            lblNoteInfo.Text = LineInput(1)

            Do Until EOF(1)

                lblNoteInfo.Text += vbCrLf & LineInput(1)

            Loop

            FileClose(1)

        Catch e As Exception

            lblNoteInfo.Text = "No Skin Information Available"

        End Try

Edited by bangbang023
  • 0
  bangbang023 said:
  devgrp said:
Try this

Try
	File.Open("myfile.txttch ex As FileNotFoundException
	lblMessage.Text = "File not found"
End Try

thanx I finally found my answer in MSDN thought. Your code wasn't 100% correct.

  Quote
Try

? ? ? ? ? ? FileOpen(1, skinChoice & "\readme.txt", OpenMode.Input)

? ? ? ? ? ? lblNoteInfo.Text = LineInput(1)

? ? ? ? ? ? Do Until EOF(1)

? ? ? ? ? ? ? ? lblNoteInfo.Text += vbCrLf & LineInput(1)

? ? ? ? ? ? Loop

? ? ? ? ? ? FileClose(1)

? ? ? ? Catch e As Exception

? ? ? ? ? ? lblNoteInfo.Text = "No Skin Information Available"

? ? ? ? End Try

actually, his code is correct and concise...

use this syntax for Try-Catch block

Try
 ?normal code
Catch exc1 As FirstException
 ?exception-handling code for FirstException
Catch exc2 As SecondException
 ?exception-handling code for SecondException
.
.
Catch
 ?exception-handling code for any remaining exceptions
Finally
 ?clean-up code
End Try

the only problem with his code was the FileOpen syntax

Try
 ? ? FileOpen(1, "\myfile.txt", OpenMode.Input)
Catch exp As IO.FileNotFoundException
 ? ? lblMessage.Text = "File not found"
End Try

and then you can change whatever in the Try block, i.e. do whatever you want with the file.

for example, you could use the Do Until EOF OR use a StreamReader and then use sr.peek way.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.