nec2++ 2.1.1
nec_exception.h
1/***************************************************************************
2 * Copyright (C) 2004-2008 by Tim Molteno *
3 * tim@physics.otago.ac.nz *
4 * *
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 2 of the License, or *
8 * (at your option) any later version. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20#pragma once
21
22#include <string>
23#include <sstream>
24
25//#include "common.h"
26
28{
29public:
31 {
32 }
33
34 nec_exception(const char* message)
35 {
36 m_message << message;
37 }
38
39 nec_exception(const char* message, int code)
40 {
41 m_message << message << code;
42 }
43
44 nec_exception(const nec_exception& other)
45 {
46 m_message << other.m_message.str();
47 }
48
49 template <class T> void append(const T& message)
50 {
51 m_message << message;
52 }
53
54 std::string get_message() const
55 {
56 return m_message.str();
57 }
58
59 static std::string string_printf(const char* fmt, ...);
60
61protected:
62 std::stringstream m_message;
63};
64
65#ifdef _MSC_VER
66/*
67 Visual C++ does not allow macros with variable argument lists. Therefore error messages
68 will be meaningless when this is compiled using VC++, however at least it will compile!
69*/
70inline void nec_stop(const char* __fmt, ...)
71{
72 nec_exception __nex("Undefined Error");
73 // __nex->os_printf(__fmt, __VA_ARGS__);
74 throw __nex;
75}
76#else
77#define nec_stop(__fmt, ...)\
78{ nec_exception __nex;\
79 std::string _mess = nec_exception::string_printf(__fmt, __VA_ARGS__); \
80 __nex.append(_mess.c_str()); \
81 throw __nex; \
82}
83#endif
Definition nec_exception.h:28