[Gambas-user] Try Catch fail when using mkdir....

Stephen Bungay sbungay at ...981...
Thu Jun 30 14:59:23 CEST 2011


Hi folks!

Gambas 2.99
Fedora 14

   Using mkdir with "catch" and "finally" to create a recursive SUB to 
build a directory structure.
   The harness consists of FormMain with one big-friendly button on it, 
pretty simple. Here is all of the code;

' Gambas class file

Public Sub _new()

End

Public Sub Form_Open()

End

Private Sub CreateNewOutputFolder(psFolderSpecification As String)
   Dim sFolderSpec As String

   sFolderSpec = psFolderSpecification

   Mkdir sFolderSpec

   Finally
     Mkdir sFolderSpec

   Catch
     sFolderSpec = Mid$(psFolderSpecification, 1, 
RInStr(psFolderSpecification, ".") - 1)
     CreateNewOutputFolder(sFolderSpec)
End

Public Sub Button1_Click()

   CreateNewOutputFolder("/home/user/Rumple/Stilskin/Was/Here")

End


   What I THINK should happen is the initial mkdir should fail, the code 
in "catch" should execute and copy the passed in parameter from position 
1 to the charcter just prior to the last "/" and then call itself 
passing in the new result as the parameter. When/if that call fails (and 
it should as this folder specification doesn't exist in my home dir) it 
again recurses. This should go on until it reaches the left-most node in 
the directory structure (AFTER the "/home/user"), and THAT one 
("/home/user/Rumple) should be the first to succeed in being created. 
The call stack should then unwind, and as it does, the previous SUBS on 
the stack should execute their "Finally" section. When the stack has 
completely unwound the directory structure should exist.... only that is 
not what is happening.
   The first Catch doesn't execute (although the directory does not get 
created.. meaning an error did indeed occur) and it skips directly to 
the "finally". When the mkdir in the "finally" is executed  (same 
parameter string because we have not yet recursed) the error "File or 
Directory does not exist" pops up on the screen. Well there's the error 
that I expected from the initial mkdir, but the "catch" didn't execute, 
anybody got ideas?




More information about the User mailing list