iOS Question RandomAccessFile - prevent crashes

Alexander Stolte

Expert
Licensed User
Longtime User
Hey,

during WriteB4XObject the app crashes, so the file is maybe damaged, if I try to read the file now, the app crashes.
I put the reading in a try catch block, the problem is it doesn't prevent the app from crashing the same happens with writing.

B4X:
Try
    
        If File.Exists(TokenFolder, TokenFile) Then
            Dim raf As RandomAccessFile
            raf.Initialize(TokenFolder, TokenFile, True)
            If raf.ReadB4XObject(raf.CurrentPosition) <> Null Then '<--crash'
                ti = raf.ReadB4XObject(raf.CurrentPosition)
            End If
    
            raf.Close
        End If
    Catch
        Log(LastException)
        File.Delete(TokenFolder,TokenFile)
    End Try

what can I do about it?
 
Top