Bug 10026 – Allow to assert that exception must be thrown
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-03T18:55:00Z
Last change time
2015-06-09T05:13:49Z
Assigned to
nobody
Creator
stpasha
Comments
Comment #0 by stpasha — 2013-05-03T18:55:02Z
I'd like to suggest that existing syntax for assert() keyword was enhanced in order to allow detection of exception thrown by the expression provided. It may look like this:
assert!(DivisionByZero)( powermod(2, 1000, 0) );
assert!(InvalidArgument)( fastsqrt(-42) );
(or it may look otherwise, I'm not really an expert in language syntax).
The reason for such functionality to exist is that "assert" is used for unit-testing of a class or module. Correct handling of errors is part of the specification of any non-trivial class, and the "D way" to handle errors is by throwing exceptions. Which current assert cannot test.
What do you think?
Comment #1 by bearophile_hugs — 2013-05-03T19:25:02Z