Summary: assertExceptionThrown to assert that a particular
                    exception was thrown
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Jonathan M Davis <> 2010-08-14 
21:11:36 PDT ---
I would love a function in std.exception which could be used with unit tests to
verify that a particular exception was thrown rather than verify the return
value of a function. So, instead of writing

    assert(0, "Exception not thrown");
catch(Exception e)

you'd write something like

assertExceptionThrown(func(/*...*/), Exception);

where you give it the function call and the exception type to catch, which
would then translate to the code above. Now, I'm not sure that you can get
quite that syntax, since you'd be passing a function call with arguments and
all rather a function pointer or delegate with arguments, but there might be a
way to do it more like

assertExceptionThrown(Exception, &func, /*...*/);

and give it a function pointer or delegate with arguments. I'm not enough of a
template wiz to know the best way to build assertExceptionThrown() (I'm not
even sure that I know enough yet to build it all), so I don't know the best way
to do it, but it seems like it should be possible one way or another. And it
would certainly be useful.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to