JuliaLang/julia — pull request #1597 by toivoh (2012-11-22 19:20:50+00:00)
Title: RFC: @expect macro, extended version

Alternative, extended version on #1594.
* Make `assert`/`@assert` always throw an `AssertionError`, so that a catcher can distinguish such an
internal error from invocation errors.
* Make `@expect` take an optional second argument to be passed to `error`,
to facilitate easy and descriptive reporting of invocation errors.

Examples:

julia> function psquare(x)
@expect x>=0 DomainError
x^2
end

julia> psquare(-4)
DomainError()
in anonymous at no file:38
in psquare at none:37

julia> function psquare(x)
@expect x>=0 ArgumentError(_msg)
x^2
end

julia> psquare(-4)
ArgumentError("expected (x>=0) == true")
in anonymous at no file:38
in psquare at none:37

The `_msg` variable is set in the scope where the second argument to `@expect` is evaluated.
I'm not sure whether this is a feature.