exitdarterror-code

How can I exit my Dart (vm) program?


(Sorry, I know that is this is mostly a repeat of John Evan's question, but the previous answer must now be outdated.)

I'd like to be able to specify an exitCode and leave the my (vm) program if a certain condition occurs (for debugging purposes only).

Note from the above I cannot import 'dart:builtin', and I can't find mention of exit() in this context in the API.

(My more detailed situation is that my work involves rather massive detailed output and as I test and debug things I have found it most convenient to just exit(); the program - clearly only appropriate during development.)

Thanks,

_g


Solution

  • Further searching has shown that the required support is now in the 'io' library so this is working for me:

    (Nothing specific to an error code is getting printed out at the console, but that's ok.)

    import('dart:io');
    
    main() {
        print("just before the exit command...");
        exit(99);
        print("We should not see this")
    }