Save As Text IOException

just add a new feature in a self contained window.

The window have a ListBox and some buttons: Open, Save, Close.

When I save the result, the application (running in the IDE) crash.

If I change the detination folder: works fine to save in its .Parent. If I go up to its .Parent, then choose the very same Folder: it works fine.

Before asking for help, I exported that window,
add it (drag and drop) to a brand new project,
Run, Open, Save: all is well in an imperfect world.

SAME CODE: no change. The “old” project is still loaded…

Run again the project and check the generated file: it is complete and correct: the result I was awaiting.

I even left El Capitan, boot with a High Sierra.

I fired Disk Utilities and check my hard disk.

I cleared the cache.

Before you ask, here is the code:

Sub Action()
  Dim Save_Dlg As New SaveAsDialog
  Dim Save_FI  As FolderItem
  Dim Save_TOS As TextOutputStream
  Dim CharName As String
  // Open the Dialog nto the Open folder
  If gOpen_FI <> Nil Then
    Save_Dlg.InitialDirectory = gOpen_FI
    CharName = NthField(gOpen_FI.Name, " - ", 1) + " - Index.txt" 
    CharName = "Set a character name.txt"
  End If
  Save_Dlg.PromptText        = "Set a Name to the Text File"
  Save_Dlg.SuggestedFileName = CharName
  Save_Dlg.Title             = "Exportation de la liste"
  Save_Dlg.Filter            = FT_IO.TEXT
  Save_FI = Save_Dlg.ShowModal()
  If Save_FI = Nil then
  End If
  // Saves the ListBox contents
  If Save_FI <> Nil Then
      // Get a TextOutputStream
      Save_TOS = TextOutputStream.Create(Save_FI)
        // a. Save the Heading Contents
        Save_TOS.WriteLine LB.Heading(-1)
        // b. Save the Lists Rows Contents
        Save_TOS.WriteLine LB.Cell(-1,-1)
        // c. Close the now useless TextOutputStream
        Save_TOS = Nil
      End Try
    Catch e As IOException
    End Try
  End If
End Sub

I am as blind as a normal person face to its own code.

IOException is not a crash and will tell you exactly what the problem is. Inspect the Message property. We can’t tell anything about the problem without that information.

1 Like

is it significant that the inner TRY has no matching CATCH?

I do not think so, the code fomes from an example in the LR.

Message ?

Where / how do I get it ?

Xojo 2015r1.

BTW: THANK YOU for your answers.

It’s a property of the raised exception. Your code catches and then ignores exceptions. If you have the IDE “Break on Exceptions” feature enabled, the debugger will pop up when it happens. You can inspect the message from there as well.

The debugger says IOException on this line:

Save_TOS = TextOutputStream.Create(Save_FI)

What is the Message property of the IOException?

Error: -1407
Message: Blank
Reason: Blank

That is all I get. I will reboot and try once more.

Okay, from the documentation, IOException error codes are from the OS.

I think you’re on Mac, right?

Heading to osstatus and looking up that error code, it shows this:

Framework: CarbonCore
Error Name: errFSNotAFolder

I quickly searched Google for information on that error, but it looks like there’s some deep diving to do. You may want to do some searching to figure out how you’re getting the problem, and then how you might fix it.

1 Like

I had no clue about that, but it was my suspicion.

If this is really the case, then the error comes from the FolderItem (gOpen_FI) I use at the top of the code. will check in the debugger what is its contents at the beginning of the code.
The only answer is that it point to a file, not to a folder.

Its time to dinner - here - and my stomach is on its knees asking (crying) for some meal.

Thank you for your time and good answers.

That was it.

The FolderItem passed as InitialDirectory points to a file.

The dialog opens correctly, but apparently, that reference is used to build the reference to save the file if you click in OK. If you choose another Folder, all is OK.

This error is so easy to be done !