VOOZH about

URL: https://www.geeksforgeeks.org/dart/how-to-exit-a-dart-application-unconditionally/

⇱ How to Exit a Dart Application Unconditionally? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Exit a Dart Application Unconditionally?

Last Updated : 15 Jul, 2025

The exit() method exits the current program by terminating the running Dart VM. This method takes a status code. A non-zero value of status code is generally used to indicate abnormal termination. This is a similar exit in C/C++, Java. This method doesn't wait for any asynchronous operations to terminate.

Syntax:

exit(exit_code);

To use this method, we have to import 'dart:io' package. The handling of exit codes is platform-specific.

  • On Linux and OS, an exit code for normal termination will always be in the range of 0 to 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 errors (unhandled exceptions). Due to these facts, it is recommended to only use exit codes in the range of 0 to 127 for communicating the result of running a Dart program to the surrounding environment. This will avoid any cross-platform issues.

Note: The exit(0) is generally used to indicate successful termination, while the rest generally indicates unsuccessful termination.


Using the exit() method to exit the program abruptly

Example:


Output:

Hello GeeksForGeeks
Comment
Article Tags:
Article Tags:

Explore