Click here to Skip to main content
15,893,594 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionPathTooLongException and Solutions? Pin
treddie3-May-13 9:38
treddie3-May-13 9:38 
AnswerRe: PathTooLongException and Solutions? Pin
Eddy Vluggen5-May-13 9:43
professionalEddy Vluggen5-May-13 9:43 
GeneralRe: PathTooLongException and Solutions? Pin
treddie5-May-13 9:50
treddie5-May-13 9:50 
GeneralRe: PathTooLongException and Solutions? Pin
Eddy Vluggen5-May-13 10:04
professionalEddy Vluggen5-May-13 10:04 
QuestionHow do i save all opened windows Pin
Member 46241693-May-13 3:16
Member 46241693-May-13 3:16 
AnswerRe: How do i save all opened windows Pin
GuyThiebaut3-May-13 4:23
professionalGuyThiebaut3-May-13 4:23 
QuestionHow do i save all opened windows Pin
Member 46241693-May-13 2:56
Member 46241693-May-13 2:56 
QuestionTry Catch does not Execute Catch code Pin
treddie2-May-13 18:31
treddie2-May-13 18:31 
Hi all.

I was trying this TreeView demo and ran into a situation where a Try Catch block will not pass execution onto the Catch code. The error is "Drive not ready" when attempting to access a:\. That is easy enough to understand...I have no floppy on my system. But why does the error handler not pass the error to the Catch area?

Many thanks for any advice!

Here is the demo:

A form just has a TreeView and a button on it. The demo populates a TreeView with the directories of my file system:

VB
Public Class Form1

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Get a list of drives
    Dim drives As System.Collections.ObjectModel.ReadOnlyCollection(Of IO.DriveInfo) = My.Computer.FileSystem.Drives
    Dim rootDir As String = String.Empty

    'Now loop thru each drive and populate the treeview:
    For i As Integer = 0 To drives.Count - 1
      rootDir = drives(i).Name

      'Add this drive as a root node:
      TreeView1.Nodes.Add(rootDir)

      'Populate this root node:
      PopulateTreeView(rootDir, TreeView1.Nodes(i))
    Next

  End Sub

  Private Sub PopulateTreeView(ByVal dir As String, ByVal parentNode As TreeNode)
    Dim folder As String = String.Empty

    Try
      Dim folders() As String = IO.Directory.GetDirectories(dir)

      If folders.Length <> 0 Then
        Dim childNode As TreeNode = Nothing

        For Each folder In folders
          childNode = New TreeNode(folder)
          parentNode.Nodes.Add(childNode)
          PopulateTreeView(folder, childNode)
        Next
      End If

    Catch ex As UnauthorizedAccessException
      parentNode.Nodes.Add(folder & ": Access Denied")

    End Try

  End Sub

End Class


modified 3-May-13 3:17am.

AnswerRe: Try Catch does not Execute Catch code Pin
Richard MacCutchan2-May-13 21:41
mveRichard MacCutchan2-May-13 21:41 
GeneralRe: Try Catch does not Execute Catch code Pin
treddie2-May-13 22:02
treddie2-May-13 22:02 
QuestionMethod signature does not match delegate - thread safe Pin
Member 100187622-May-13 7:12
Member 100187622-May-13 7:12 
AnswerRe: Method signature does not match delegate - thread safe Pin
Richard Deeming2-May-13 8:21
mveRichard Deeming2-May-13 8:21 
GeneralRe: Method signature does not match delegate - thread safe Pin
Member 100187622-May-13 11:00
Member 100187622-May-13 11:00 
GeneralRe: Method signature does not match delegate - thread safe Pin
Alan N2-May-13 12:26
Alan N2-May-13 12:26 
QuestionTrouble passing arguments to System.Diagnostics.Process.Start Pin
savedlema2-May-13 0:07
savedlema2-May-13 0:07 
AnswerRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Richard MacCutchan2-May-13 1:07
mveRichard MacCutchan2-May-13 1:07 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Richard Deeming2-May-13 1:23
mveRichard Deeming2-May-13 1:23 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Richard MacCutchan2-May-13 1:27
mveRichard MacCutchan2-May-13 1:27 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
savedlema2-May-13 8:06
savedlema2-May-13 8:06 
AnswerRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Eddy Vluggen2-May-13 5:07
professionalEddy Vluggen2-May-13 5:07 
AnswerRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Alan N2-May-13 5:44
Alan N2-May-13 5:44 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
savedlema2-May-13 8:01
savedlema2-May-13 8:01 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Alan N2-May-13 8:17
Alan N2-May-13 8:17 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
savedlema3-May-13 0:54
savedlema3-May-13 0:54 
GeneralRe: Trouble passing arguments to System.Diagnostics.Process.Start Pin
Alan N3-May-13 2:57
Alan N3-May-13 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.