GLBasic forum

Feature request => IDE/Syntax => Topic started by: FutureCow on 2009-Apr-21

Title: Exit with message
Post by: FutureCow on 2009-Apr-21
It would be good to have the equivalent of the "die" perl command so that you can abort the program with an error message. For example it would be good to be able to easily output "Error : Failed to set graphics mode" or similar.
Title: Re: Exit with message
Post by: Kitty Hello on 2009-Apr-21
Code (glbasic) Select

FUNCTION Die: message$
BLACKSCREEN
PRINT message$,0,0
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION
Title: Re: Exit with message
Post by: Schranz0r on 2009-Apr-21
Win32(on a separat gbas):

Code (glbasic) Select
INLINE
    extern "C" {
        DECLARE_ALIAS(exportMessageBoxA, "user32.dll", "MessageBoxA", (void*, const char*, const char*, unsigned int), int);
    } // close the extern "C"
ENDINLINE


FUNCTION Win32MessageBox: text$, caption$
INLINE // of course, GLBAsic does not know about "exportMessageBoxA" - only INLINE does
   if(exportMessageBoxA)
      return exportMessageBoxA(0, text_Str.c_str(), caption_Str.c_str(), 0);
ENDINLINE
ENDFUNCTION


Thats a WinApi-Messagebox :)

Title: Re: Exit with message
Post by: FutureCow on 2009-May-28
Thanks for the WinApi call Schranz0r - that will be useful.

But say for example you tried to initialise a 1024x768x32 mode and the graphics card didn't support it. How would you display a error message with that?
Title: Re: Exit with message
Post by: Schranz0r on 2009-May-28
see:

http://www.glbasic.com/forum/index.php?topic=961.0
Title: Re: Exit with message
Post by: FutureCow on 2009-May-28
Cool, that will be helpful.

I was hoping though for a generic error message command. It seems that there really isn't much error handling in GLBasic and I would prefer to be able to catch and handle errors rather than having the program ignore them :-
eg. If any of the following fail
* You tried to load a graphic that doesn't exist
* You tried to write data to the network when the network connection had closed
* You tried to save data to a file and the save failed (full disk etc)
etc

I would like to be able to get return codes on commands that have a good chance of failing (pretty much the input / output to devices commands)
Title: Re: Exit with message
Post by: Kitty Hello on 2009-May-28
OK, sounds like a good idea. Implementing a "lastError$()" function, that returns somthing like:
"001 File not found", where you could either cast it to a number to do error checking, or just display the text.
Title: Re: Exit with message
Post by: FutureCow on 2009-May-28
Awesome - cheers Gernot!!!