In Pitonyak's book it lists Shell as returning a runtime error if the program being run is not found. Unfortunately this does not seem to be working. I can successfully catch other errors but if the program Shell() is trying to run is not found it either locks soffice at 100% of CPU or causes it to crash completely!
Here's an example:
Code: Select all
Sub BrokenShell
On Error Goto ErrorHandler
Dim iNumber As Integer
Dim iCount As Integer
Dim sLine As String
Dim aFile As String
' An example of an error that gets caught
aFile = "/some/broken/url"
iNumber = Freefile
Open aFile For Output As #iNumber
Print #iNumber, "This is a line of text"
Close #iNumber
iNumber = Freefile
Open aFile For Input As iNumber
For iCount = 1 to 5
Line Input #iNumber, sLine
Next iCount
Close #iNumber
Proceed:
msgbox("But can I catch this error?")
'Shell( "bash -c " + cQuote + "bash --version", "",6,true) 'This is a working shell example
' A few examples of broken shell commands that cause crashes
Shell("brokenname", "", 6,true) 'Crash
'Shell("brokenname", "", 6,false) 'Crash
'Shell("brokenname", "", 6) 'Crash
'Shell("brokenname") 'Locks up the program using 100% CPU time, nothing happens
msgbox("No error")
Exit Sub
ErrorHandler:
msgbox("That was an error and I handled it!")
Reset
Resume Proceed
End Sub
Interested to know if anyone else has any ideas. I'd be tempted to file a bug on this if it can't be worked around.