-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy patherror.jl
34 lines (28 loc) · 848 Bytes
/
error.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Transcoding Error
# =================
"""
Container of transcoding error.
An object of this type is used to notify the caller of an exception that
happened inside a transcoding method. The `error` field is undefined at first
but will be filled when data processing failed. The error should be set by
calling the `setindex!` method (e.g. `error[] = ErrorException("error!")`).
"""
mutable struct Error
error::Exception
function Error()
return new()
end
end
# Test if an exception is set.
function haserror(error::Error)
return isdefined(error, :error)
end
function Base.setindex!(error::Error, ex::Exception)
@assert !haserror(error) "an error is already set"
error.error = ex
return error
end
function Base.getindex(error::Error)
@assert haserror(error) "no error is set"
return error.error
end