From 0e6d7972c62eb1dedaf00ea9b966a0060e2effb8 Mon Sep 17 00:00:00 2001 From: Octogonapus Date: Fri, 19 Jul 2024 01:22:28 +0200 Subject: [PATCH] Clean up some docs issues (#55139) - #55055: Remove incorrect BoundsError mention from iterate(string) docs. - #54686: Document the else keyword in the try/catch docs. Closes #55055. Closes #54686. --- base/docs/basedocs.jl | 14 ++++++++++++++ base/strings/basic.jl | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 19bafbe3de3a4..37804d1d9a380 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -1050,6 +1050,17 @@ 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/catch` block can also have an `else` clause that executes only if no exception occurred: +```julia +try + a_dangerous_operation() +catch + @warn "The operation failed." +else + @info "The operation succeeded." +end +``` + 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: @@ -1064,6 +1075,9 @@ finally end ``` (`finally` can also be used without a `catch` block.) + +!!! compat "Julia 1.8" + Else clauses require at least Julia 1.8. """ kw"try", kw"catch" diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 2d5f0cea26e36..bf11199143c1e 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -146,9 +146,8 @@ Stacktrace: Return a tuple of the character in `s` at index `i` with the index of the start of the following character in `s`. This is the key method that allows strings to -be iterated, yielding a sequences of characters. If `i` is out of bounds in `s` -then a bounds error is raised. The `iterate` function, as part of the iteration -protocol may assume that `i` is the start of a character in `s`. +be iterated, yielding a sequences of characters. The `iterate` function, as part +of the iteration protocol may assume that `i` is the start of a character in `s`. See also [`getindex`](@ref), [`checkbounds`](@ref). """