Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 535 Bytes

managing-run-time-errors-exceptions.md

File metadata and controls

28 lines (23 loc) · 535 Bytes

7 - Managing run-time errors (exceptions)

Run-time errors can be handled with the try/catch block:

try
  # ..some dangerous code..
catch
  # ..what to do if an error happens, most likely send an error message using:
  error("My detailed message")
end

You can also check for a specific type of exception, e.g.:

function volume(region, year) 
    try
        return data["volume",region,year]
    catch  e
        if isa(e, KeyError)
          return missing
        end
        rethrow(e)
    end
end