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.
FUNCTION Die: message$
BLACKSCREEN
PRINT message$,0,0
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION
Win32(on a separat gbas):
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 :)
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?
see:
http://www.glbasic.com/forum/index.php?topic=961.0
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)
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.
Awesome - cheers Gernot!!!