// vim: ft=cpp #pragma once /* * exceptions -- * * Romain exception definitions. * * (c) 2011-2012 Björn Döbel , * economic rights: Technische Universität Dresden (Germany) * This file is part of TUD:OS and distributed under the terms of the * GNU General Public License 2. * Please see the COPYING-GPL-2 file for details. */ #include #include // snprintf etc. #include // L4::Base_error class Romain_error : public L4::Base_exception { public: enum {data_size = 100}; protected: char _func[data_size]; unsigned _line; public: Romain_error(char const *func, unsigned line) : _line(line) { snprintf(_func, data_size, "At \033[34m%s:%d\033[0m: ", func, line); _func[data_size-1] = 0; } virtual const char *str() const throw() { return _func; } }; #define _check(cond, message) \ do { \ if (cond) { \ void *pc[10]; \ int cnt; \ ERROR() << __FILE__ << " " << __func__ << " " << message; \ cnt = l4util_backtrace(pc, 10); \ for (int i = 0; i < cnt; ++i) { \ ERROR() << std::hex << l4_umword_t(pc[i]); \ } \ enter_kdebug(message); \ } \ } while (0); /* * Argument error exception. Contains a description about * the missing argument and the location where it occurred. */ class Argument_error : public Romain_error { char _data[Romain_error::data_size*2]; public: Argument_error(char const *func, unsigned line, char const *msg) : Romain_error(func, line) { snprintf(_data, sizeof(_data), "%s%s\n", _func, msg); } virtual const char *str() const throw() { return _data; } };