00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Vegard Nossum * 00003 * vegard.nossum@gmail.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 3 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #pragma once 00022 00031 #include <exception> 00032 #include <string> 00033 00037 class Assertion : public std::exception 00038 { 00039 public: 00049 Assertion(const char* expr, 00050 const char* file, unsigned int line, 00051 const char* func, const char* pretty_func); 00052 00054 ~Assertion() throw(); 00055 00056 public: 00058 const char *what() const throw(); 00059 00060 private: 00061 std::string m_msg; 00062 }; 00063 00065 #define Assert(x) \ 00066 if(!(x)) { \ 00067 throw Assertion("" # x, \ 00068 __FILE__, __LINE__, \ 00069 __FUNCTION__, __PRETTY_FUNCTION__); \ 00070 }