• 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.
  • Posts

    • Samsung could unveil its Galaxy XR headset ‘Project Moohan' in September by Sagar Naresh Bhavsar Next month, Samsung is expected to unveil the Galaxy Z Fold7, the Galaxy Z Flip7, and an affordable Galaxy Z Flip7 FE, along with the Galaxy Watch8 series. However, the launches don't end there. A fresh report out of South Korea hints that Samsung could launch its much-awaited Galaxy XR augmented reality headset in September. The company has codenamed its first XR headset as "Project Moohan," which translates to "Project Infinite." Samsung has already showcased the Galaxy XR headset a few times in the past. In fact, popular tech YouTuber Marques Brownlee - also known as MKBHD -, got his hands on the Galaxy XR and revealed interesting details about the upcoming device. The Galaxy XR is rumored to come with a sharper display compared to the Apple Vision Pro and run on Google's new operating system for AR and VR headsets, the Android XR. Fast forward to now, Korean publication Newspim reports that Samsung is ready to launch the Galaxy XR headset on September 29 in its home country. Notably, the headset will be unveiled at an Unpacked event and later will go on sale on October 13. Globally, the Galaxy XR headset is expected to launch soon afterwards, though any specific date isn't mentioned. Additionally, the report suggests that fans can expect more teaser videos and prototypes of the headset at the upcoming Unpacked event for the Galaxy Z Fold7 and Flip7. The report also spills some details about the specifications of the Galaxy XR headset. Under the hood, it could run on Qualcomm's new XR2+ Gen 2 chip, made using Samsung's 4nm process. Samsung is also expected to introduce tight integration with its Galaxy ecosystem to offer a connected experience. It will be interesting to see how Samsung holds up against the likes of Meta, which already dominates the XR market, while Apple struggles with high Vision Pro prices.
    • I've put it behind a login for the time being.  I had something like 600,000 requests from just from Alibaba IP addresses that didn't clarify they were bots or scrapers, and so not easy to block using user agent filtering.  I didn't have any issues with bandwidth or accessibility, but that's 600,000 requests just from one cloud provider made to my spinning rust hard drives, that I have to personally pay for when they die, by bots being ran by corrupt mega corporations ignoring my polite requests that they not scrape me and that the information only be accessed by real humans. If any of y'all here were actually using my Kiwix mirror, I have no issue whatsoever creating a username and password for you, just hit me up using one of the methods listed on my personal site and I'll make one for you. https://marcusadams.me
    • I always turn encryption off 1st boot, crazy its on by default on new computers, it should ASK you ON or OFF on 1st boot,, So many people dont even know its on , then forget their windows login and microsoft account,, RETarDED Microsoft is now, , i also find having it on slows things down too
    • Adding AI is just an excuse to hike prices. I don't want any AI features in our Slack workspace and yet will have to pay for it.
    • Hello Could you be kind too help me fix this 3.1gig and not 256gig it says 3.1gig only .someone told me to fix it with this https://www.disk-partition.com/articles/64gb-flash-drive-only-showing-32gb-5740i.html yes my sandisk ultra usb 3.0 256gb wont show up in full .  but i don't know want options i have to use on there can someone  please guide me with step by step instructions please  guide me with step by step instructions on how to repair this .sorry for asking but I've tried but i don't know want i have to do on that programme please help me i am on windows 11 home thank you nick
  • Recent Achievements

    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
    • Week One Done
      TBithoney earned a badge
      Week One Done
    • First Post
      xuxlix earned a badge
      First Post
    • First Post
      Tomek Święcicki earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      675
    2. 2
      ATLien_0
      288
    3. 3
      Michael Scrip
      223
    4. 4
      +FloatingFatMan
      195
    5. 5
      Steven P.
      144
  • Tell a friend

    Love Neowin? Tell a friend!