this post was submitted on 25 Jun 2023
400 points (98.3% liked)

Programmer Humor

31995 readers
410 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 1 year ago (3 children)

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

[–] [email protected] 26 points 1 year ago* (last edited 1 year 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 4 points 1 year ago (1 children)

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

[–] [email protected] 16 points 1 year ago

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

readFile() or die;

die unless $a > $b;

[–] [email protected] 3 points 1 year ago

exit()-ing your step-sys already seems pretty explicit...