Skip to content

Commit 4479a8a

Browse files
committed
new try catch in printfmt
1 parent cf67f99 commit 4479a8a

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/fmtspec.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,34 +172,35 @@ function printfmt(io::IO, fs::FormatSpec, x)
172172
cls = fs.cls
173173
ty = fs.typ
174174
if cls == 'i'
175+
local ix
175176
try
176177
ix = Integer(x)
177-
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
178-
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
179-
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
180-
ty == 'o' ? _pfmt_i(io, fs, ix, _Oct()) :
181-
_pfmt_i(io, fs, ix, _Bin())
182178
catch
183-
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, x, _Dec()) :
184-
ty == 'x' ? _pfmt_i(io, fs, x, _Hex()) :
185-
ty == 'X' ? _pfmt_i(io, fs, x, _HEX()) :
186-
ty == 'o' ? _pfmt_i(io, fs, x, _Oct()) :
187-
_pfmt_i(io, fs, x, _Bin())
179+
ix = x
188180
end
181+
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
182+
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
183+
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
184+
ty == 'o' ? _pfmt_i(io, fs, ix, _Oct()) :
185+
_pfmt_i(io, fs, ix, _Bin())
189186
elseif cls == 'f'
187+
local fx, nospecialf
190188
try
191189
fx = float(x)
192-
if isfinite(fx)
193-
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, fx) :
194-
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, fx) :
195-
error("format for type g or G is not supported yet (use f or e instead).")
196-
else
197-
_pfmt_specialf(io, fs, fx)
198-
end
199190
catch
200-
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, x) :
201-
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, x) :
191+
fx = x
192+
end
193+
try
194+
nospecialf = isfinite(fx)
195+
catch
196+
nospecialf = true
197+
end
198+
if nospecialf
199+
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, fx) :
200+
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, fx) :
202201
error("format for type g or G is not supported yet (use f or e instead).")
202+
else
203+
_pfmt_specialf(io, fs, fx)
203204
end
204205
elseif cls == 's'
205206
_pfmt_s(io, fs, _srepr(x))

0 commit comments

Comments
 (0)