Skip to content

Commit

Permalink
document finally in try/catch (#54269)
Browse files Browse the repository at this point in the history
As noted [on
discourse](https://discourse.julialang.org/t/try-catch-online-help/113532),
the `try` docstring should at least briefly mention `finally`.

---------

Co-authored-by: Sukera <[email protected]>
  • Loading branch information
2 people authored and DilumAluthge committed Jun 3, 2024
1 parent f8a4c54 commit 5bfa338
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5bfa338

Please sign in to comment.