ErrorLevel

BlitzMax Forums/BlitzMax Programming/ErrorLevel

ziggy(Posted 2005) [#1]
Is there any way to stop the execution of a BlitzMax application returning an errorlevel?
I would like to end execution and return an Errorlevel from within a method of a type.


Robert(Posted 2005) [#2]
Not at the moment.

If you look at the C code in the BRL.AppStub module, the main() function always returns 0.

The entry point to the BlitzMAX code is the _bb_main() function which is declared void, so it cannot return a value.

I think it would be quite easy for Mark to modify the source so that a value could be returned though.


ziggy(Posted 2005) [#3]
Thanks Robert!


Dreamora(Posted 2005) [#4]
hmm

Do you somehow mean something like a "try - throw - catch" combination with runtime error?


ziggy(Posted 2005) [#5]
No, I mean, when an application ends, it returns a value to the OS. by default the value is zero (it means no error), but If an error occurs, then you can tell the OS (or the calling application who has started the one that has caused the error) another number.
As isntance:
'--- file error.bmx ----
print "hello, where going to load a image"
Local MyImage:TImage = LoadImage("something.bmp")
if MyImage = 0 or MyImage = Null then
    Print "Image was not loaded"
    EndWithError 1   'this doesn't exists
Endif

And what does the OS do with the error returned?
by default Nothing, but this errorlevel can be checked later to ensure the application has run without errors.
BMK, for example, returns an errorlevel different to 0 when the application wasn't compiled for any reason (syntax error or whatever).


StuC(Posted 2005) [#6]
Actually, you could call the ExitProcess(uExitCode) Win32 function (I'm sure there are equivalents for Linux/Mac).

It's declared in Kernel32.dll

Cheers,

Stu


Robert(Posted 2005) [#7]
I forgot about that one.

I think it would be best if Mark were to make some simple (I hope!) modifications to BlitzMAX so that the error code could be returned the conventional way, since this would be guaranteed not to suffer any unfortunate side-effects (for example, with ExitProcess, any functions in the OnEnd list will not be executed)


marksibly(Posted 2005) [#8]
Hi,

The C function 'exit_' should do the trick, eg: 'exit_ 1000'.

This will call the C atexit_ list (which is what OnEnd actually uses) so should perform a clean shutdown.

Perhaps I should add an optional parameter to 'End' as well?


LarsG(Posted 2005) [#9]
Perhaps I should add an optional parameter to 'End' as well?

yeah.. sounds nice..


ziggy(Posted 2005) [#10]
An optional parameter should be very nice and clean. :)