www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10026] New: Allow to assert that exception must be thrown

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10026

           Summary: Allow to assert that exception must be thrown
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: stpasha gmail.com


--- Comment #0 from Pasha S <stpasha gmail.com> 2013-05-03 18:55:02 PDT ---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10026


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2013-05-03 19:25:02 PDT ---
See:

http://dlang.org/phobos/std_exception.html

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10026


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |WONTFIX


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-05-04
03:54:18 PDT ---
Use assertThrown and assertNotThrown from std.exception.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 04 2013