]> git.saurik.com Git - apple/system_cmds.git/blobdiff - CPPUtil/UtilException.hpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / CPPUtil / UtilException.hpp
diff --git a/CPPUtil/UtilException.hpp b/CPPUtil/UtilException.hpp
new file mode 100644 (file)
index 0000000..1452eb6
--- /dev/null
@@ -0,0 +1,34 @@
+//
+//  Exception.hpp
+//  CPPUtil
+//
+//  Created by James McIlree on 4/7/13.
+//  Copyright (c) 2013 Apple. All rights reserved.
+//
+
+#ifndef CPPUtil_Exception_hpp
+#define CPPUtil_Exception_hpp
+
+class Exception : public std::exception {
+    protected:
+       std::string _what;
+
+    public:
+       Exception(std::string& what) : _what(what) {} ;
+       virtual ~Exception() throw () {};
+       
+       virtual char const* what() const throw() { return _what.c_str(); }
+};
+
+#define THROW(e)                       \
+{                                      \
+       std::ostringstream s;           \
+       s << e;                         \
+       std::string str = s.str();      \
+       Exception exp(str);             \
+       throw exp;                      \
+}
+
+#define UNIMPLEMENTED() THROW("Unimplemented: " << Path((char*)__FILE__).basename() << ":" << __LINE__ )
+
+#endif