forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.jl
70 lines (56 loc) · 1.64 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This file is a part of Julia. License is MIT: http://julialang.org/license
@test map(typeof, map(@catch(i->[1,2,3][i]), 1:6)) ==
[Int, Int, Int, BoundsError, BoundsError, BoundsError]
@test typeof(@catch(open)("/no/file/with/this/name")) == SystemError
let
function foo_error(c, n)
c[1] += 1
if c[1] <= n
error("foo")
end
return 7
end
# Success on first attempt
c = [0]
@test retry(foo_error)(c,0) == 7
@test c[1] == 1
# Success on second attempt
c = [0]
@test retry(foo_error)(c,1) == 7
@test c[1] == 2
# Success on third attempt
c = [0]
@test retry(foo_error)(c,2) == 7
@test c[1] == 3
# 3 failed attempts, so exception is raised
c = [0]
ex = @catch(retry(foo_error))(c,3)
@test ex.msg == "foo"
@test c[1] == 3
c = [0]
ex = @catch(retry(foo_error, ErrorException))(c,3)
@test typeof(ex) == ErrorException
@test ex.msg == "foo"
@test c[1] == 3
c = [0]
ex = @catch(retry(foo_error, e->e.msg == "foo"))(c,3)
@test typeof(ex) == ErrorException
@test ex.msg == "foo"
@test c[1] == 3
# No retry if condition does not match
c = [0]
ex = @catch(retry(foo_error, e->e.msg == "bar"))(c,3)
@test typeof(ex) == ErrorException
@test ex.msg == "foo"
@test c[1] == 1
c = [0]
ex = @catch(retry(foo_error, e->e.http_status_code == "503"))(c,3)
@test typeof(ex) == ErrorException
@test ex.msg == "foo"
@test c[1] == 1
c = [0]
ex = @catch(retry(foo_error, SystemError))(c,3)
@test typeof(ex) == ErrorException
@test ex.msg == "foo"
@test c[1] == 1
end