Dynamic dispatch in `catch` clauses


#1

Docs tell that one could create user-defined exception types simply subtyping Exception. But how to use those? In other languages we can use multiple catch clauses. Doesn’t Julia have ones?

struct MyEx <: Exception end

try
    # ...
catch (ex :: MyEx)
    println("My exception")
catch
    println("Any other exception")
end

#2

I think at the moment you need to do something like this:

julia> try
           error("foo")
       catch e
           if isa(e, ErrorException)
               println("bar")
           else
               rethrow(e)
           end
       end
bar