forked from whoozle/clunk
-
Notifications
You must be signed in to change notification settings - Fork 4
/
clunk_ex.h
58 lines (47 loc) · 1.84 KB
/
clunk_ex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef CLUNK_EXCEPTION_H__
#define CLUNK_EXCEPTION_H__
/* libClunk - cross-platform 3D audio API built on top SDL library
* Copyright (C) 2007-2008 Netive Media Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <exception>
#include <string>
#include "logger.h"
namespace clunk {
class CLUNKAPI Exception : public std::exception {
public:
Exception() throw() {}
void add_message(const char *file, int line);
void add_message(const std::string &msg);
virtual void add_custom_message() {}
virtual ~Exception() throw() {}
virtual const char* what() const throw() { return message.c_str(); }
private:
std::string message;
};
class CLUNKAPI IOException : public Exception {
public:
virtual void add_custom_message();
};
}
#define throw_generic(ex_cl, fmt) { ex_cl e; e.add_message(__FILE__, __LINE__); e.add_message(clunk::format_string fmt ); e.add_custom_message(); throw e; }
#define throw_ex(fmt) throw_generic(clunk::Exception, fmt)
#define throw_io(fmt) throw_generic(clunk::IOException, fmt)
#define TRY try
#define CATCH(where, code) catch(const std::exception &_e) {\
LOG_ERROR(("%s: %s", where, _e.what())); \
code;\
}
#endif