forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.j
25 lines (19 loc) · 812 Bytes
/
error.j
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
## native julia error handling ##
error(e::Exception) = throw(e)
error{E<:Exception}(::Type{E}) = throw(E())
error(s::ByteString) = throw(ErrorException(s))
error(s...) = error(print_to_string(print, s...))
## system error handling ##
errno() = ccall(:jl_errno, Int32, ())
strerror(e::Int) = ccall(:jl_strerror, Any, (Int32,), int32(e))::ByteString
strerror() = strerror(errno())
system_error(p::String, b::Bool) = b ? error(SystemError(p)) : true
system_error(s::Symbol, b::Bool) = system_error(string(s), b)
## assertion functions and macros ##
assert_test(b::Bool) = b
assert_test(b::Tensor{Bool}) = all(b)
assert(x) = assert(x,'?')
assert(x,labl) = assert_test(x) ? true : error("Assertion failed: ", labl)
macro assert(ex)
:(assert_test($ex) ? true : error("Assertion failed: ", $string(ex)))
end