From 93d2cec44d9a8f2890509fd2013e6dfd0d4deb80 Mon Sep 17 00:00:00 2001 From: Arhik Date: Tue, 18 Jun 2024 08:41:40 +0530 Subject: [PATCH] [DOCS] FieldError exception FieldError was introduced in #54504. This PR adds documentation for the same. --- base/docs/basedocs.jl | 27 +++++++++++++++++++++++++++ doc/src/base/base.md | 1 + doc/src/manual/control-flow.md | 1 + 3 files changed, 29 insertions(+) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 0ae04c147a227c..38a61faadcc1ec 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -1637,9 +1637,36 @@ julia> ex = ErrorException("I've done a bad thing"); julia> ex.msg "I've done a bad thing" ``` + +!!! compat "Julia 1.12" + ErrorException should no longer be used to raise exceptions for invalid field access. Use FieldError instead. + """ ErrorException +""" + FieldError(type, field) + +An operation tried to access invalid `field` of `type`. + +# Examples +```jldoctest +julia> struct AB + a::Float32 + b::Float64 + end + +julia> ab = AB(1, 3) +AB(1.0f0, 3.0) + +julia> ab.c # field `c` doesn't exist +ERROR: FieldError: type AB has no field c +Stacktrace: +[...] +``` +""" +FieldError + """ WrappedException(msg) diff --git a/doc/src/base/base.md b/doc/src/base/base.md index 03a12e81fe6738..f2673d00748415 100644 --- a/doc/src/base/base.md +++ b/doc/src/base/base.md @@ -414,6 +414,7 @@ Core.DivideError Core.DomainError Base.EOFError Core.ErrorException +Base.FieldError Core.InexactError Core.InterruptException Base.KeyError diff --git a/doc/src/manual/control-flow.md b/doc/src/manual/control-flow.md index 4096f334f93708..ed6f26725f87cd 100644 --- a/doc/src/manual/control-flow.md +++ b/doc/src/manual/control-flow.md @@ -601,6 +601,7 @@ below all interrupt the normal flow of control. | [`DomainError`](@ref) | | [`EOFError`](@ref) | | [`ErrorException`](@ref) | +| [`FieldError`](@ref) | | [`InexactError`](@ref) | | [`InitError`](@ref) | | [`InterruptException`](@ref) |