the stacktrace has cityindex:62
, which is likely where your function definition originally is?
if so, yes, the interpolation ALWAYS happens, not just when the error is thrown
note also the docstring of @assert
:
│ Warning
│
│ An assert might be disabled at various optimization levels. Assert should therefore only be used as a
│ debugging tool and not used for authentication verification (e.g., verifying passwords), nor should
│ side effects needed for the function to work correctly be used inside of asserts.
So at various optimization levels, the @assert
may be removed entirely, leading to a wrong result. I'd suggest the pattern
isnothing(i) || throw(ArgumentError(LazyString("City ", c, " not found"))
which will stay in your code across optimization levels and only interpolate the string when the error is actually thrown.
Laura Demkowicz-Duffy has marked this topic as resolved.
Laura Demkowicz-Duffy has marked this topic as resolved.
Last updated: Oct 02 2023 at 04:34 UTC