GLBasic forum

Feature request => IDE/Syntax => Topic started by: FutureCow on 2013-Jun-02

Title: Error Handling
Post by: FutureCow on 2013-Jun-02
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.
Title: Re: Error Handling
Post by: Moru on 2013-Jun-02
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.
Title: Re: Error Handling
Post by: FutureCow on 2013-Jun-03
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.
Title: Re: Error Handling
Post by: MrTAToad on 2013-Jun-07
I think I mentioned this sort of thing years ago :)  It would be nice to have...
Title: Re: Error Handling
Post by: hardyx on 2013-Jun-27
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

Title: Re: Error Handling
Post by: spacefractal on 2013-Jun-28
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.