Exit with message

Previous topic - Next topic

FutureCow

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.

Kitty Hello

Code (glbasic) Select

FUNCTION Die: message$
BLACKSCREEN
PRINT message$,0,0
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION

Schranz0r

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 :)

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

FutureCow

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?

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

FutureCow

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)

Kitty Hello

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.

FutureCow

Awesome - cheers Gernot!!!