ATLAS Offline Software
Loading...
Searching...
No Matches
expect_exception.h File Reference

Helper to check that an exception is thrown. More...

#include <cassert>
Include dependency graph for expect_exception.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXPECT_EXCEPTION(EXC, CODE)
 Helper to check that an exception is thrown.

Detailed Description

Helper to check that an exception is thrown.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Aug, 2014

Definition in file expect_exception.h.

Macro Definition Documentation

◆ EXPECT_EXCEPTION

#define EXPECT_EXCEPTION ( EXC,
CODE )
Value:
do { \
bool caught = false; \
try { \
CODE; \
} \
catch (const EXC&) { \
caught = true; \
} \
assert (caught); \
} while(0)

Helper to check that an exception is thrown.

Use like this:

EXPECT_EXCEPTION (std::runtime_error, doSomething());
#define EXPECT_EXCEPTION(EXC, CODE)
Helper to check that an exception is thrown.

This will produce an assertion failure if doSomething() does not throw a std::runtime_error exception.

Definition at line 33 of file expect_exception.h.

33#define EXPECT_EXCEPTION(EXC, CODE) do { \
34 bool caught = false; \
35 try { \
36 CODE; \
37 } \
38 catch (const EXC&) { \
39 caught = true; \
40 } \
41 assert (caught); \
42} while(0)