@debug
(and other logging macros like @info
& co) are meant to log messages, so I’m not sure that’s what you want here.
The standard @assert
is closer to what you’d want, but AFAIK it is not so easy to control whether checks are actually performed at run-time or not. So in your case, I’d probably use something like ToggleableAsserts – see the relevant discussion about this here on discourse:
You example could be written something like (untested):
using ToggleableAsserts
function my_func(a::Int)
@toggled_assert (a + 2 < 0) "a + 2 cannot be negative"
# Perform real calculation here.
return a
end
And you can call toggle(true)
or toggle(false)
to decide whether you want checks to actually be performed (debug mode) or be elided (performance mode)