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

Docs: Warn that thrown exceptions cannot be relied on #50669

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion doc/src/manual/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,14 @@ Stacktrace:
[...]
```

Note that the symbol following `catch` will always be interpreted as a name for the exception,
Note that the specific type of exception thrown of Julia code in Base and the
standard libraries, (in this case, a `DomainError` or a `BoundsError`)
is considered an internal implementation detail and may change across minor
versions of Julia.
Therefore, users are adviced not to write code like the code above which relies
on specific exception types, unless they are explicitly documented.

In `catch` statements, the symbol following `catch` will always be interpreted as a name for the exception,
so care is needed when writing `try/catch` expressions on a single line. The following code will
*not* work to return the value of `x` in case of an error:

Expand Down
6 changes: 6 additions & 0 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ Note that `@test_throws` does not support a trailing keyword form.
!!! compat "Julia 1.8"
The ability to specify anything other than a type or a value as `exception` requires Julia v1.8 or later.

!!! note
The type and text of thrown exceptions is considered an implementation detail,
and may change in minor versions of Julia.
The generic `@test_throws Exception expr` may be used to test for exceptions
generally.

# Examples
```jldoctest
julia> @test_throws BoundsError [1, 2, 3][4]
Expand Down