Blitz3D+ Command Reference

FilesystemErrorCode ( )

Parameters

None.

Description

Returns the raw error code of the last recoverable filesystem failure.

Where FilesystemError gives prose, this gives the number your code can branch on. For ordinary failures it is the unmodified Win32 error code - 2 is ERROR_FILE_NOT_FOUND ("no save yet - show the new-game screen"), 5 is ERROR_ACCESS_DENIED, 32 is a sharing violation, 112 is disk full. That lets a save system distinguish "first run" from "genuine problem" without parsing message text.

A few failures are detected by the Application Data package itself rather than Windows - invalid UTF-8 in text or a path, or a package limit being hit - and those report stable package-specific codes instead, so the code is always meaningful.

Set together with FilesystemError and FilesystemErrorPath whenever a command in this family fails (LoadJson, the atomic writers, CreateDirTree, the SHA-256 file commands), and cleared by the next successful operation - read it straight after the failed call. Context-local like its companions.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: FilesystemError, FilesystemErrorPath, WriteTextAtomic, Sha256File.

Example

; FilesystemErrorCode Example
; ---------------------------
; Requires Extended mode.

; Try to hash a save file that does not exist - a recoverable
; failure that returns empty and sets the filesystem diagnostics
digest$=Sha256File("missing_save_example.json")
Print "Sha256File returned '"+digest+"' (empty = failed)"
Print ""

; FilesystemErrorCode returns the raw Win32 (or package) error
; code - 2 is ERROR_FILE_NOT_FOUND
code=FilesystemErrorCode()
Print "FilesystemErrorCode: "+code
If code=2 Then Print "Code 2 is ERROR_FILE_NOT_FOUND."
Print ""

; Its companions describe the failure and name the path involved
Print "FilesystemError: "+FilesystemError()
Print "FilesystemErrorPath: "+FilesystemErrorPath()

Print ""
Print "Press any key to close the example"
WaitKey

End

Index