KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Why is `MissingExternalProgramError` not a subtype of `Exception`? #199

Closed DilumAluthge closed 4 years ago

DilumAluthge commented 4 years ago

MissingExternalProgramError is defined here as:

struct MissingExternalProgramError
    str::AbstractString
end

Is there any particular reason why MissingExternalProgramError is not a subtype of Exception?

KristofferC commented 4 years ago

What does it matter?

DilumAluthge commented 4 years ago

All exceptions in Base are subtypes of Exception, and the manual recommends doing the same for custom errors:

You may define your own exceptions in the following way: julia> struct MyCustomException <: Exception end

In one of my use cases, I catch all exceptions during execution of a program and log them at the end. I store them in a Vector{Exception}, which seems appropriate given the quote from the manual. Unfortunately this fails if I try to push a MissingExternalProgramError into that Vector.

I think it's reasonable for a caller to expect that anything that is thrown is a subtype of Exception.

DilumAluthge commented 4 years ago

In my use case, I fixed the problem by switching to using a Vector{Any} to store the exceptions. But in general I think it's good practice for things that are thrown to be subtypes of Exception.