diff options
author | Araq <rumpf_a@web.de> | 2015-04-10 11:58:17 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-04-10 14:03:47 +0200 |
commit | 3a9500f7b102c4cfd10dd551e0c4b40449492351 (patch) | |
tree | 534432dca5a44bd4159f8e231f66ed68f2894cd9 /lib/system.nim | |
parent | 6e6c6446a4d3d30a7e97ef4417bdca892e376b53 (diff) | |
download | Nim-3a9500f7b102c4cfd10dd551e0c4b40449492351.tar.gz |
fixes #2500
Diffstat (limited to 'lib/system.nim')
-rw-r--r-- | lib/system.nim | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/lib/system.nim b/lib/system.nim index 52c29f757..83f071717 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3044,13 +3044,12 @@ template currentSourcePath*: string = instantiationInfo(-1, true).filename proc raiseAssert*(msg: string) {.noinline.} = sysFatal(AssertionError, msg) -when true: - proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} = - # trick the compiler to not list ``EAssertionFailed`` when called - # by ``assert``. - type THide = proc (msg: string) {.noinline, raises: [], noSideEffect, - tags: [].} - THide(raiseAssert)(msg) +proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} = + # trick the compiler to not list ``AssertionError`` when called + # by ``assert``. + type THide = proc (msg: string) {.noinline, raises: [], noSideEffect, + tags: [].} + THide(raiseAssert)(msg) template assert*(cond: bool, msg = "") = ## Raises ``AssertionError`` with `msg` if `cond` is false. Note @@ -3115,24 +3114,18 @@ when not defined(nimhygiene): template onFailedAssert*(msg: expr, code: stmt): stmt {.dirty, immediate.} = ## Sets an assertion failure handler that will intercept any assert - ## statements following `onFailedAssert` in the current lexical scope. - ## Can be defined multiple times in a single function. + ## statements following `onFailedAssert` in the current module scope. ## ## .. code-block:: nim - ## - ## proc example(x: int): ErrorCode = - ## onFailedAssert(msg): - ## log msg - ## return E_FAIL - ## - ## assert(...) - ## - ## onFailedAssert(msg): - ## raise newException(MyError, msg) - ## - ## assert(...) - ## - template failedAssertImpl(msgIMPL: string): stmt {.dirty, immediate.} = + ## # module-wide policy to change the failed assert + ## # exception type in order to include a lineinfo + ## onFailedAssert(msg): + ## var e = new(TMyError) + ## e.msg = msg + ## e.lineinfo = instantiationInfo(-2) + ## raise e + ## + template failedAssertImpl(msgIMPL: string): stmt {.dirty.} = let msg = msgIMPL code |