3 ms·
Many programming languages will exit 1 for unexpected exceptions at runtime (or programmer error). Eg, this Ruby program will exit 1: $ ruby -e 'raise Stan
by jitl 5y ago
Many programming languages will exit 1 for unexpected exceptions at runtime (or programmer error). Eg, this Ruby program will exit 1:
$ ruby -e 'raise StandardError.new "oops"'
Traceback (most recent call last):
-e:1:in `<main>': oops (StandardError)
$ echo $?
1
And so will this one:
$ ruby -e 'invalid method call'
Traceback (most recent call last):
-e:1:in `<main>': undefined local variable or method `call' for main:Object (NameError)
Did you mean? caller
So, it's nice to distinguish between a possibly unexpected exceptional exit (1), and an "error case detected by the programmer", which is what I use exit (2) for.