1- const Try{T} = Union{Stop {<: Exception }, Identity{T}}
1+ const Try{T} = Union{Const {<: Exception }, Identity{T}}
22Try (t) = Identity (t)
3- Try (t:: Exception ) = Stop (t)
3+ Try (t:: Exception ) = Const (t)
44Try {T} (t:: T ) where T = Identity (t)
5- Try {T} (other) where T = Stop (other)
5+ Try {T} (other) where T = Const (other)
66
77
88
99"""
10- Failure is like Exception, however can also cary stacktraces
10+ Thrown is like Exception, however can also cary stacktraces
1111"""
12- struct Failure {E} <: Exception
12+ struct Thrown {E} <: Exception
1313 exception:: E
1414 stacktrace:: Vector
1515end
1616
1717# == controversy https://github.com/JuliaLang/julia/issues/4648
18- function Base.:(== )(a:: Failure , b:: Failure )
18+ function Base.:(== )(a:: Thrown , b:: Thrown )
1919 a. exception == b. exception && a. stack == b. stack
2020end
2121
22+ function Base. show (io:: IO , x:: Thrown )
23+ print (io, " Thrown($(repr (x. exception)) )" )
24+ end
2225
2326# Multiline version, following https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing-1
24- function Base. show (io:: IO , :: MIME"text/plain" , exc:: Failure {E} ) where {E}
25- println (io, " Failure{ $E } ($(repr (exc. exception)) )" )
27+ function Base. show (io:: IO , :: MIME"text/plain" , exc:: Thrown {E} ) where {E}
28+ println (io, " Thrown ($(repr (exc. exception)) )" )
2629 for (exc′, bt′) in exc. stacktrace
2730 showerror (io, exc′, bt′)
2831 println (io)
2932 end
3033end
31- function Base. showerror (io:: IO , :: MIME"text/plain" , exc:: Failure )
34+ function Base. showerror (io:: IO , :: MIME"text/plain" , exc:: Thrown )
3235 Base. show (io, MIME " text/plain" (), exc)
3336end
3437
@@ -66,9 +69,9 @@ function Base.showerror(io::IO, ::MIME"text/plain", exc::MultipleExceptions)
6669 Base. show (io, MIME " text/plain" (), exc)
6770end
6871
69- Base. merge (f1:: Failure , f2:: Failure ) = MultipleExceptions ((f1, f2))
70- Base. merge (f:: Failure , e:: Exception ) = MultipleExceptions ((f, e))
71- Base. merge (e:: Exception , f:: Failure ) = MultipleExceptions ((e, f))
72+ Base. merge (f1:: Thrown , f2:: Thrown ) = MultipleExceptions ((f1, f2))
73+ Base. merge (f:: Thrown , e:: Exception ) = MultipleExceptions ((f, e))
74+ Base. merge (e:: Exception , f:: Thrown ) = MultipleExceptions ((e, f))
7275Base. merge (es:: MultipleExceptions , e:: Exception ) = MultipleExceptions (tuple (es. exceptions... , e))
7376Base. merge (e:: Exception , fs:: MultipleExceptions ) = MultipleExceptions (tuple (e, fs. exceptions... ))
7477Base. merge (es1:: MultipleExceptions , es2:: MultipleExceptions ) = MultipleExceptions (tuple (es1. exceptions... , es2. exceptions... ))
@@ -79,20 +82,20 @@ promote_rule(::Type{Try{T}}, ::Type{Try{S}}) where {T, S<:T} = Try{T}
7982
8083
8184
82- # typejoin Failure & Failure
83- # Base.typejoin(::Type{Failure {E}}, ::Type{Failure {E}}) where E = Failure {E}
84- # Base.typejoin(::Type{<:Failure }, ::Type{<:Failure }) = Failure
85+ # typejoin Thrown & Thrown
86+ # Base.typejoin(::Type{Thrown {E}}, ::Type{Thrown {E}}) where E = Thrown {E}
87+ # Base.typejoin(::Type{<:Thrown }, ::Type{<:Thrown }) = Thrown
8588# # typejoin Identity & Identity
8689# Base.typejoin(::Type{Identity{T}}, ::Type{Identity{T}}) where T = Identity{E}
8790# Base.typejoin(::Type{<:Identity}, ::Type{<:Identity}) = Identity
88- # # typejoin Failure & Identity
89- # Base.typejoin(::Type{Failure {E}}, ::Type{Identity{T}}) where {T, E} = Try{T, E}
90- # Base.typejoin(::Type{Identity{T}}, ::Type{Failure {E}}) where {T, E} = Try{T, E}
91- # # typejoin Failure & Try
92- # Base.typejoin(::Type{Failure {E}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
93- # Base.typejoin(::Type{<:Try{T, E}}, ::Type{Failure {E}}) where {T, E} = Try{T, E}
94- # Base.typejoin(::Type{<:Failure }, ::Type{<:Try{T}}) where T = Try{T}
95- # Base.typejoin(::Type{<:Try{T}}, ::Type{<:Failure }) where T = Try{T}
91+ # # typejoin Thrown & Identity
92+ # Base.typejoin(::Type{Thrown {E}}, ::Type{Identity{T}}) where {T, E} = Try{T, E}
93+ # Base.typejoin(::Type{Identity{T}}, ::Type{Thrown {E}}) where {T, E} = Try{T, E}
94+ # # typejoin Thrown & Try
95+ # Base.typejoin(::Type{Thrown {E}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
96+ # Base.typejoin(::Type{<:Try{T, E}}, ::Type{Thrown {E}}) where {T, E} = Try{T, E}
97+ # Base.typejoin(::Type{<:Thrown }, ::Type{<:Try{T}}) where T = Try{T}
98+ # Base.typejoin(::Type{<:Try{T}}, ::Type{<:Thrown }) where T = Try{T}
9699# # typejoin Identity & Try
97100# Base.typejoin(::Type{Identity{T}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
98101# Base.typejoin(::Type{<:Try{T, E}}, ::Type{Identity{T}}) where {T, E} = Try{T, E}
@@ -115,7 +118,7 @@ macro Try(expr)
115118 r = $ (esc (expr))
116119 Identity {typeof(r)} (r)
117120 catch exc
118- Stop ( Failure (exc, Base. catch_stack ()))
121+ Const ( Thrown (exc, Base. catch_stack ()))
119122 end
120123 end
121124end
@@ -128,7 +131,7 @@ macro TryCatch(exception, expr)
128131 Identity {typeof(r)} (r)
129132 catch exc
130133 if exc isa $ (esc (exception))
131- Stop ( Failure (exc, Base. catch_stack ()))
134+ Const ( Thrown (exc, Base. catch_stack ()))
132135 else
133136 rethrow ()
134137 end
@@ -137,12 +140,12 @@ macro TryCatch(exception, expr)
137140end
138141
139142issuccess (:: Identity ) = true
140- issuccess (:: Stop {<:Exception} ) = false
143+ issuccess (:: Const {<:Exception} ) = false
141144
142- isfailure (:: Identity ) = false
143- isfailure (:: Stop {<:Exception} ) = true
145+ isexception (:: Identity ) = false
146+ isexception (:: Const {<:Exception} ) = true
144147
145148Base. eltype (:: Type{<:Try{T}} ) where T = T
146149Base. eltype (:: Type{<:Try} ) = Any
147- # somehow the normal Stop eltype got broken
148- Base. eltype (:: Type{<:Stop {<:Exception}} ) = Any
150+ # somehow the normal Const eltype got broken
151+ Base. eltype (:: Type{<:Const {<:Exception}} ) = Any
0 commit comments