]> git.saurik.com Git - apple/system_cmds.git/blob - CPPUtil/UtilException.hpp
1452eb66428bebac64635618d6c641aa17d79eb0
[apple/system_cmds.git] / CPPUtil / UtilException.hpp
1 //
2 // Exception.hpp
3 // CPPUtil
4 //
5 // Created by James McIlree on 4/7/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
7 //
8
9 #ifndef CPPUtil_Exception_hpp
10 #define CPPUtil_Exception_hpp
11
12 class Exception : public std::exception {
13 protected:
14 std::string _what;
15
16 public:
17 Exception(std::string& what) : _what(what) {} ;
18 virtual ~Exception() throw () {};
19
20 virtual char const* what() const throw() { return _what.c_str(); }
21 };
22
23 #define THROW(e) \
24 { \
25 std::ostringstream s; \
26 s << e; \
27 std::string str = s.str(); \
28 Exception exp(str); \
29 throw exp; \
30 }
31
32 #define UNIMPLEMENTED() THROW("Unimplemented: " << Path((char*)__FILE__).basename() << ":" << __LINE__ )
33
34 #endif