diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 7b9faa8eb1d23..6268274f0e9ec 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -1058,13 +1058,28 @@ exception object to the given variable within the `catch` block. The power of the `try`/`catch` construct lies in the ability to unwind a deeply nested computation immediately to a much higher level in the stack of calling functions. + +A `try` or `try`/`catch` block can also have a [`finally`](@ref) clause that executes +at the end, regardless of whether an exception occurred. For example, this can be +used to guarantee that an opened file is closed: +```julia +f = open("file") +try + operate_on_file(f) +catch + @warn "An error occurred!" +finally + close(f) +end +``` +(`finally` can also be used without a `catch` block.) """ kw"try", kw"catch" """ finally -Run some code when a given block of code exits, regardless +Run some code when a given `try` block of code exits, regardless of how it exits. For example, here is how we can guarantee that an opened file is closed: