Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document finally in try/catch #54269

Merged
merged 6 commits into from
May 24, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,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
println("An error occurred!")
stevengj marked this conversation as resolved.
Show resolved Hide resolved
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:

Expand Down