• lowleveldata
    link
    fedilink
    arrow-up
    5
    ·
    2 years ago

    I have never used System.exit() or sys.exit(). What is a use case where you would call these explicitly?

    • niq@discuss.tchncs.de
      link
      fedilink
      arrow-up
      25
      ·
      edit-2
      2 years ago

      For example if you want to set an explicit exit code. Calling python scripts will usually result in an exit code 0 after the script is run. If you want to set a different exit code for example 1 to indicate some error occured you can do that via sys.exit(1).

      Same thing applies to other languages of course.

    • epyon22@sh.itjust.works
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      2 years ago

      Applications where you aren’t using some sort of framework. Usually MVC or other frameworks would handle this or are designed to continuously run.

      • jsveiga@vlemmy.net
        link
        fedilink
        arrow-up
        16
        ·
        2 years ago

        Perl is funnier, as these are valid ways of exiting with an exception:

        readFile() or die;

        die unless $a > $b;