Author Topic: Error Handling  (Read 3076 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Error Handling
« 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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: Error Handling
« Reply #1 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.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Error Handling
« Reply #2 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.

MrTAToad

  • Guest
Re: Error Handling
« Reply #3 on: 2013-Jun-07 »
I think I mentioned this sort of thing years ago :)  It would be nice to have...

Online hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 491
    • View Profile
Re: Error Handling
« Reply #4 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
« Last Edit: 2013-Jun-27 by hardyx »

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3669
    • View Profile
    • Space Fractal
Re: Error Handling
« Reply #5 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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.