On Fri, Nov 11 2016, Angel de Vicente wrote:

> Tamas Papp <tkp...@gmail.com> writes:
>>> But return will only quit the current function and return execution to
>>> the caller. Coming from Fortran, I also miss something like STOP, which
>>> will stop all execution and return me to the REPL.
>>
>> I hear you --- I miss RETURN-FROM from Common Lisp.
>>
>> Simply throwing an error will stop execution and return to the REPL
>> though.
>
> Yes, I was using that, but it is not very clean. It gives the wrong
> impression that an error happened (which in many cases it is probably
> true, but not always) plus it prints the call stack at the point of the
> error. If error() could be told to be silent, it would be almost
> perfect. Anyway, a minor thing.

immutable Stop <: Exception end

function run_task(f)
    try f()
    catch e
        if isa(e, Stop)
            println("Your program was gracefully terminated.")
        else
            rethrow()
        end
    end
end

function f()
    throw(Stop())
end

function g()
    f()
end

julia>  run_task() do
            g()
        end
Your program was gracefully terminated.

julia>  run_task() do
            error("This is bad.")
        end
ERROR: This is bad.
 in run_task(::##84#85) at ./REPL[167]:2

Reply via email to