This routine correct traps the first occurrence, however on second occurrence, the trap does not work and QB64 attempts to open a non-existent file and I get a pop-up error (assuming from the compiler).
I'm sure I'm missing something simple (like clearing the error state), but figured the 'ON ERROR GOTO 0" would handle it properly.
Thanks in advance.
Title: Re: Trapping "File Not Found" Errors
Post by: Petr on June 25, 2020, 12:12:32 pm
You can save yourself from trouble by checking if _FILEEXISTS first before trying to open it.
Exactly. Check for the file existing first. You don't want to invoke an error if you don't have to. Just do this: Modification: Use BINARY instead of INPUT for much faster reading of a file.
Title: Re: Trapping "File Not Found" Errors
Post by: doppler on June 25, 2020, 03:11:09 pm
False positive if the directory does not exists so _DIREXISTS(filepath$)
Title: Re: Trapping "File Not Found" Errors
Post by: TempodiBasic on June 25, 2020, 04:58:20 pm
Hi bryandj23
1. I agree with other QB64 coders, better to use _FILEEXSISTS than ON ERROR GOTO .... RESUME
2. you get one run of error trapping because you disable the error handler read help on wiki about ON ERROR GOTO https://www.qb64.org/wiki/ON_ERROR (https://www.qb64.org/wiki/ON_ERROR) as you can read ON ERROR GOTO 0 disables the error Handler! To let you run your code you must REM the line on ERROR GOTO 0 Moreover to reset the error trapping you must return from ErrorTrappingSub_Function using RESUME (that triggers again the error) or RESUME NEXT (that activates the next line of code after the ErrorTrigger)