Nice. Thanks!

>> 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
>

-- 
Ángel de Vicente
http://www.iac.es/galeria/angelv/          

Reply via email to