1 /***************************************************************************
2 * Copyright (C) 2008 by Vegard Nossum *
3 * vegard.nossum@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 * This file contains the Assertion exception and macro.
35 * This exception is thrown when an assertion fails.
37 class Assertion
: public std::exception
41 * Constructs an assertion with the specified attributes.
43 * @param expr The expression of the assertion that failed.
44 * @param file The file in which the assertion failed.
45 * @param line The line in which the assertion failed.
46 * @param func The function in which the assertion failed.
47 * @param pretty_func A 'pretty' name of the function in which the assertion failed.
49 Assertion(const char* expr
,
50 const char* file
, unsigned int line
,
51 const char* func
, const char* pretty_func
);
53 /** Destructor, a noop. */
57 /** Override the msg of this exception to describe the assertion failure.*/
58 const char *what() const throw();
61 std::string m_msg
; /**< The msg that describes the failed assertion. */
64 /** Assert that x is true, if it is not an Assertion exception is thrown. */
67 throw Assertion("" # x, \
69 __FUNCTION__, __PRETTY_FUNCTION__); \