Julia language: a concise tutorial
  • Introduction
  • Language core
    • 1 - Getting started
    • 2 - Data types
    • 3 - Control flow
    • 4 - Functions
    • 5 - Custom structures
    • 6 - Input - Output
    • 7 - Managing run-time errors (exceptions)
    • 8 - Interfacing Julia with other languages
    • 9 - Metaprogramming
    • 10 - Performance (parallelisation, debugging, profiling..)
    • 11 - Developing Julia packages
  • Useful packages
    • Plotting
    • DataFrames
    • JuMP
    • SymPy
    • Weave
    • LAJuliaUtils
    • IndexedTables
    • Pipe
Powered by GitBook
On this page
  1. Language core

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
Previous6 - Input - OutputNext8 - Interfacing Julia with other languages

Last updated 6 years ago