From e10e0393a29265c0c4a3858453c68465091bdd0c Mon Sep 17 00:00:00 2001 From: Jaehyung Lee Date: Tue, 10 Nov 2015 00:11:16 +0900 Subject: [PATCH 1/2] doc: fix outdated output msg in the assert example [av skip] --- doc/manual/metaprogramming.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/metaprogramming.rst b/doc/manual/metaprogramming.rst index 6cbeaa42c0c8d..de3cdbafd91cc 100644 --- a/doc/manual/metaprogramming.rst +++ b/doc/manual/metaprogramming.rst @@ -545,7 +545,7 @@ This macro can be used like this: julia> @assert 1==1.0 julia> @assert 1==0 - ERROR: AssertionError: 1 == 0 + ERROR: Assertion failed: 1 == 0 In place of the written syntax, the macro call is expanded at parse time to its returned result. This is equivalent to writing:: From 8f21bd3e18efbcda6f4dcdd6b754db20ec9debab Mon Sep 17 00:00:00 2001 From: Jaehyung Lee Date: Tue, 10 Nov 2015 01:30:09 +0900 Subject: [PATCH 2/2] doc: fix the assert example to be consistent with doctest output [av skip] --- doc/manual/metaprogramming.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/manual/metaprogramming.rst b/doc/manual/metaprogramming.rst index de3cdbafd91cc..128f174c05001 100644 --- a/doc/manual/metaprogramming.rst +++ b/doc/manual/metaprogramming.rst @@ -535,7 +535,7 @@ Building an advanced macro Here is a simplified definition of Julia's :obj:`@assert` macro:: macro assert(ex) - return :($ex ? nothing : error("Assertion failed: ", $(string(ex)))) + return :( $ex ? nothing : throw(AssertionError($(string(ex)))) ) end This macro can be used like this: @@ -545,13 +545,13 @@ This macro can be used like this: julia> @assert 1==1.0 julia> @assert 1==0 - ERROR: Assertion failed: 1 == 0 + ERROR: AssertionError: 1 == 0 In place of the written syntax, the macro call is expanded at parse time to its returned result. This is equivalent to writing:: - 1==1.0 ? nothing : error("Assertion failed: ", "1==1.0") - 1==0 ? nothing : error("Assertion failed: ", "1==0") + 1==1.0 ? nothing : throw(AssertionError("1==1.0")) + 1==0 ? nothing : throw(AssertionError("1==0")) That is, in the first call, the expression ``:(1==1.0)`` is spliced into the test condition slot, while the value of ``string(:(1==1.0))`` is @@ -572,8 +572,8 @@ ellipses following the last argument:: macro assert(ex, msgs...) msg_body = isempty(msgs) ? ex : msgs[1] - msg = string("assertion failed: ", msg_body) - return :($ex ? nothing : error($msg)) + msg = string(msg_body) + return :($ex ? nothing : throw(AssertionError($msg))) end Now :obj:`@assert` has two modes of operation, depending upon the number of