exit function

void exit (int code)

Exit the Dart VM process immediately with the given exit code.

This does not wait for any asynchronous operations to terminate. Using exit is therefore very likely to lose data.

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.


void exit(int code) {
  if (code is! int) {
    throw new ArgumentError("Integer value for exit code expected");
  if (!_EmbedderConfig._mayExit) {
    throw new UnsupportedError(
        "This embedder disallows calling dart:io's exit()");