@@ -36,11 +36,35 @@ export DataFormat,
36
36
stream,
37
37
unknown
38
38
39
+ import Base. showerror
40
+
39
41
include (" query.jl" )
40
42
include (" loadsave.jl" )
41
43
include (" registry.jl" )
42
44
45
+ @doc """
46
+ `LoaderError` should be thrown when loader library code fails, and other libraries should
47
+ be given the chance to recover from the error. Reports the library name and an error message:
48
+ LoaderError("ImageMagick", "Foo not available")
49
+ """ ->
50
+ type LoaderError <: Exception
51
+ library:: UTF8String
52
+ msg:: UTF8String
53
+ end
54
+ Base. showerror (io:: IO , e:: LoaderError ) = println (io, e. library, " load error: " ,
55
+ msg, " \n Will try next loader." )
43
56
57
+ @doc """
58
+ `WriterError` should be thrown when writer library code fails, and other libraries should
59
+ be given the chance to recover from the error. Reports the library name and an error message:
60
+ WriterError("ImageMagick", "Foo not available")
61
+ """ ->
62
+ type WriterError <: Exception
63
+ library:: UTF8String
64
+ msg:: UTF8String
65
+ end
66
+ Base. showerror (io:: IO , e:: WriterError ) = println (io, e. library, " writer error: " ,
67
+ msg, " \n Will try next writer." )
44
68
45
69
@doc """
46
70
- `load(filename)` loads the contents of a formatted file, trying to infer
@@ -59,10 +83,14 @@ function load(s::@compat(Union{AbstractString,IO}), args...; options...)
59
83
Library = check_loader (library)
60
84
return Library. load (q, args... ; options... )
61
85
catch e
62
- last_exception = e
86
+ if isa (e, LoaderError)
87
+ info (e. library, " failed. " , e. msg)
88
+ info (" Will try next loader, if available" )
89
+ else
90
+ rethrow (e)
91
+ end
63
92
end
64
93
end
65
- rethrow (last_exception)
66
94
end
67
95
68
96
@doc """
@@ -80,10 +108,14 @@ function save(s::@compat(Union{AbstractString,IO}), data...; options...)
80
108
Library = check_saver (library)
81
109
return Library. save (q, data... ; options... )
82
110
catch e
83
- last_exception = e # TODO , better and standardized exception propagation system
111
+ if isa (e, WriterError)
112
+ info (e. library, " failed. " , e. msg)
113
+ info (" Will try next writer, if available" )
114
+ else
115
+ rethrow (e)
116
+ end
84
117
end
85
118
end
86
- rethrow (last_exception)
87
119
end
88
120
89
121
# Forced format
@@ -108,10 +140,14 @@ function Base.writemime(io::IO, mime::MIME, x)
108
140
check_mime (pkg)
109
141
return writemime (Stream (DataFormat{pkg}, io), mime, x)
110
142
catch e
111
- last_exception = e
143
+ if isa (e, WriterError)
144
+ info (e. library, " failed. " , e. msg)
145
+ info (" Will try next writer, if available" )
146
+ else
147
+ rethrow (e)
148
+ end
112
149
end
113
150
end
114
- rethrow (last_exception)
115
151
end
116
152
117
153
# Fallbacks
0 commit comments