May 2019
Beginner to intermediate
466 pages
10h 44m
English
In code that performs state changes or uses resources such as files or databases, there is typically some clean-up work (such as closing files or database connections) that needs to be done when the code is finished. This code would normally go into the try branch—but what happens if an exception is thrown?
In such cases, the finally clause comes into play. This can be added after a try or after a catch branch. The code within the finally block is guaranteed to be executed, regardless of whether exceptions are thrown or not:
julia> try getattr(dom.root, "href") catch ex println("The $(tag(dom.root)) tag doesn't have a '$(ex.key)' attribute.") finally println("I always get called") end The HTML tag doesn't have a 'href' ...Read now
Unlock full access