View source code
Display the source code in std/exception.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.exception.assertNotThrown
Asserts that the given expression does not throw the given type
of Throwable
. If a Throwable
of the given type is thrown,
it is caught and does not escape assertNotThrown. Rather, an
AssertError
is thrown. However, any other Throwable
s will escape.
auto assertNotThrown(T, E)
(
lazy E expression,
string msg = null,
string file = __FILE__,
size_t line = __LINE__
);
Parameters
Name | Description |
---|---|
T | The Throwable to test for. |
expression | The expression to test. |
msg | Optional message to output on test failure. If msg is empty, and the thrown exception has a non-empty msg field, the exception's msg field will be output on test failure. |
file | The file where the error occurred.
Defaults to __FILE__ . |
line | The line where the error occurred.
Defaults to __LINE__ . |
Throws
AssertError
if the given Throwable
is thrown.
Returns
the result of expression
.
Example
import core .exception : AssertError;
import std .string;
assertNotThrown!StringException(enforce!StringException(true, "Error!"));
//Exception is the default.
assertNotThrown(enforce!StringException(true, "Error!"));
assert(collectExceptionMsg!AssertError(assertNotThrown!StringException(
enforce!StringException(false, "Error!"))) ==
`assertNotThrown failed: StringException was thrown: Error!`);
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.