exit function
- int code
Exit the Dart VM process immediately with the given exit code.
This does not wait for any asynchronous operations to terminate nor execute
finally
blocks. Using exit is therefore very likely to lose data.
While debugging, the VM will not respect the --pause-isolates-on-exit
flag if exit is called as invoking this method causes the Dart VM
process to shutdown immediately. To properly break on exit, consider
calling debugger from dart:developer
or Isolate.pause from
dart:isolate
on Isolate.current to pause the isolate before
invoking exit.
The handling of exit codes is platform specific.
On Linux and OS X an exit code for normal termination will always
be in the range [0..255]
. If an exit code outside this range is
set the actual exit code will be the lower 8 bits masked off and
treated as an unsigned value. E.g. using an exit code of -1 will
result in an actual exit code of 255 being reported.
On Windows the exit code can be set to any 32-bit value. However some of these values are reserved for reporting system errors like crashes.
Besides this the Dart executable itself uses an exit code of 254
for reporting compile time errors and an exit code of 255
for
reporting runtime error (unhandled exception).
Due to these facts it is recommended to only use exit codes in the range [0..127] for communicating the result of running a Dart program to the surrounding environment. This will avoid any cross-platform issues.
Implementation
Never exit(int code) {
ArgumentError.checkNotNull(code, "code");
if (!_EmbedderConfig._mayExit) {
throw new UnsupportedError(
"This embedder disallows calling dart:io's exit()");
}
_ProcessUtils._exit(code);
}