Basically, is there some kind of analogue of exit(-1)
function in GNU Smalltalk 3.2.5? Or is there a way to configure it so that if it encounters an error during execution it'd return non-zero exit code? I want to be able to detect if gst
executed the st code file successfully or if an error (syntax or runtime/exception) occurred.
Asked
Active
Viewed 708 times
4

Dan M.
- 3,818
- 1
- 23
- 41
1 Answers
3
Yes, it is possible using ObjectMemory quit: 0
or ObjectMemory quit: 1
etc. The source code for ObjectMemory quit:
ObjectMemory class >> quit: exitStatus [
"Quit the Smalltalk environment, passing the exitStatus integer
to the OS. Files are closed and other similar cleanups occur."
<category: 'builtins'>
<primitive: VMpr_ObjectMemory_quit>
SystemExceptions.WrongClass signalOn: exitStatus mustBe: SmallInteger
]
Searching for 'quit' in the source code will provide examples of it in action.

ben rudgers
- 3,647
- 2
- 20
- 32
-
Well, I understand that Smalltalk doesn't really have a strong notion of anything outside its VM and that its VM might also run on some PC and needs to have a way to communicate with it too. But `gst` already supports `self halt` to halt execution, so I was wondering if there is something like `self halt:exitCode` (or why there is not). Just printing it to stdout is obviously not an option as there is no reliable way to distinguish between the text outputted by the code itself and such a makeshift error code (especially if you have little control over the program output,i.e. if it's external) – Dan M. Aug 16 '17 at 20:06
-
weel, not ideal either if the program doesn't have full control of the stderr (also, the compiler may past some syntax errors there). The question was not about logging, but about the communication of Smalltalk with the outer OS (i.e. exitCode is frequently used to tell whether the program was successful or not and a lot of other programs really on the exitCode being correctly set). Inability to communicate properly with the outer os/system just limits the use cases of Smalltalk as a language. – Dan M. Aug 16 '17 at 23:07
-
Thanks! That's exactly what I was looking for! Not really easy to find =) – Dan M. Aug 20 '17 at 01:20