Error Handling

Previous topic - Next topic

FutureCow

Can we please have error checking? You should be able to check the return code on commands like LoadSprite for example to gracefully handle if they fail rather than having your program die unexpectedly.

Moru

In ancient times there were something called "ON ERROR GOTO" so when something failed, your code would jump to some error handler that you made. You didn't have much to go on except some error code though.

FutureCow

I'm not suggesting a generic method, I'm suggesting a return code per load/creation statement. Yes, I'm aware that they would have to be individually coded on the back end, and yes, I think the amount of effort is warranted. It doesn't look very professional for your program to crash when it could instead give the user a useful error message.

MrTAToad

I think I mentioned this sort of thing years ago :)  It would be nice to have...

hardyx

#4
Or using a new language variable like LASTERR to save the last error in a I/O instruction. Old Turbo Pascal used a variable called IOError when you use a file instruction. You can use or not use, but a non zero value indicates an error has occurred.

Code (glbasic) Select
LOADSPRITE "nonexistent.png", 1
IF LASTERR <> 0
      PRINT "Error loading sprite", 0, 0
      loaded = false
ELSE
      loaded = true
ENDIF


spacefractal

uses GETSPRITESIZE as well DOESFILEEXIST to detect a file load error with sprites.

And then instead doing LOADSPRITE, cast that to a function instead, so you can do the above error checking.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/