I am getting into exception handling, but I am surprised at how my code works. Note that I am on Julia 0.6 (will port to 1.0 as soon as it’s out!). So, here goes:
function bungle(c) out = 0 try @printf "Bungling away\n" out = 1 if c == 1 @assert false @sprintf "We have a main %s undervolt" "B" elseif c==2 M = spzeros(1e4) v = randn(1e4) x = M\v elseif c==3 a = sqrt(-1.) elseif c==4 throw(DomainError()) end catch ex out = 2 @printf "\nHouston we have a problem:\n%s\n" ex.msg finally @printf "Shutting down.\n" return out end end # function bungle @show bungle(0)
Calling bungle(0) and bungle(1) behaves as I intend. Bungle(2), bungle(3) and bungle(4) throw exceptions, which should be caught and reported. However, in these cases, the catch block is not executed, while the finaly block is. Why on earth!?!