X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/CPPUtil/UtilException.hpp diff --git a/CPPUtil/UtilException.hpp b/CPPUtil/UtilException.hpp new file mode 100644 index 0000000..1452eb6 --- /dev/null +++ b/CPPUtil/UtilException.hpp @@ -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