On Monday, August 15, 2016 at 6:24:02 AM UTC, Tamas Papp wrote:
>
> You can use exit(0), but the exit code is implicitly 0 anyway when your
> Julia script runs without errors. See
> http://docs.julialang.org/en/release-0.4/stdlib/base/
Yes, I did check, the default is 1 on exception/error (there are no known
errors to me except subtypes of Exception).
julia -e "type MyCustomException <: Exception end;
throw(MyCustomException)"; echo $?
ERROR: MyCustomException
1
julia -e "throw(UnicodeError)"; echo $?
ERROR: MyCustomException
1
When is there a need to call exit(n) # with non-zero n? Or n>1; would
throwing an exception always be better than at least exit(1)?
julia> @edit throw(MyCustomException)
ERROR: ArgumentError: argument is not a generic function
in methods at ./reflection.jl:140
I can't see that anything other than 1 is ever thrown on exception [as
throw is a keyword and not really a function, so I'm not sure where to
check..]
Is there a need (or a possibility, seems not, only allows for a message (in
only one language..)) to throw exceptions with some other non-zero error
code? [I guess it's bad form to catch exceptions and then call exit.. or
call exit from atexit handler..]
This is what I found:
exit(n) = ccall(:jl_exit, Void, (Int32,), n)
exit() = exit(0)
quit() = exit()
So if at the end of your script exit() is called you get 0 exit code for
sure.
bash manual:
"An OR list has the form
command1 || command2
command2 is executed if and only if command1 returns a non-zero exit
status
[..]
? Expands to the exit status of the most recently executed foreground
pipeline.
[..]
PIPESTATUS
An array variable (see Arrays below) containing a list of
exit status values from the processes in the most-recently-executed
foreground pipeline (which may contain only a single com‐
mand).
[..]
If the name is neither a shell function nor a builtin, and contains no
slashes, bash searches each element of the PATH for a directory containing
an executable file by that name. Bash uses a
hash table to remember the full pathnames of executable files (see
hash under SHELL BUILTIN COMMANDS below). A full search of the directories
in PATH is performed only if the command is not
found in the hash table. If the search is unsuccessful, the shell
searches for a defined shell function named command_not_found_handle. If
that function exists, it is invoked with the orig‐
inal command and the original command's arguments as its arguments,
and the function's exit status becomes the exit status of the shell. If
that function is not defined, the shell prints an
error message and returns an exit status of 127.
[..]
EXIT STATUS
The exit status of an executed command is the value returned by the
waitpid system call or equivalent function. Exit statuses fall between 0
and 255, though, as explained below, the shell
may use values above 125 specially. Exit statuses from shell
builtins and compound commands are also limited to this range. Under
certain circumstances, the shell will use special values to
indicate specific failure modes.
For the shell's purposes, a command which exits with a zero exit
status has succeeded. An exit status of zero indicates success. A
non-zero exit status indicates failure. When a command
terminates on a fatal signal N, bash uses the value of 128+N as the
exit status.
If a command is not found, the child process created to execute it
returns a status of 127. If a command is found but is not executable, the
return status is 126.
If a command fails because of an error during expansion or
redirection, the exit status is greater than zero.
Shell builtin commands return a status of 0 (true) if successful,
and non-zero (false) if an error occurs while they execute. All builtins
return an exit status of 2 to indicate incorrect
usage.
Bash itself returns the exit status of the last command executed,
unless a syntax error occurs, in which case it exits with a non-zero
value. See also the exit builtin command below."
--
Palli.
>
> On Mon, Aug 15 2016, Rishabh Raghunath wrote:
>
> > I'd like to know What the equivalent of "return 0 used in C" is in
> Julia
> > while completion of program ..
>