1 /* 2 * This file is part of Wireless Display Software for Linux OS 3 * 4 * Copyright (C) 2014 Intel Corporation. 5 * 6 * Contact: Jussi Laako <jussi.laako@linux.intel.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 21 * 02110-1301 USA 22 */ 23 24 25 #ifndef MIRAC_EXCEPTION_HPP 26 #define MIRAC_EXCEPTION_HPP 27 28 #include <cstring> 29 #include <exception> 30 31 class MiracException : public std::exception 32 { 33 public: MiracException()34 MiracException () throw () 35 { } MiracException(int error_code,const char * function=NULL)36 MiracException (int error_code, const char *function = NULL) throw () 37 { 38 ec = error_code; 39 msg = strerror(ec); 40 add_func(function); 41 } MiracException(const char * error_msg,const char * function=NULL)42 MiracException (const char *error_msg, const char *function = NULL) throw () 43 { 44 msg = error_msg; 45 add_func(function); 46 } MiracException(int error_code,const char * error_msg,const char * function=NULL)47 MiracException (int error_code, const char *error_msg, const char *function = NULL) throw () 48 { 49 ec = error_code; 50 msg = std::string(error_msg) + std::string(": ") + 51 std::string(strerror(ec)); 52 add_func(function); 53 } ~MiracException()54 virtual ~MiracException () throw () 55 { } 56 what() const57 virtual const char * what () const throw () 58 { return msg.c_str(); } operator int() const59 virtual operator int () const throw () 60 { return ec; } operator std::string() const61 virtual operator std::string () const throw () 62 { return msg; } 63 64 protected: 65 int ec; 66 std::string msg; add_func(const char * function)67 void add_func (const char *function) throw () 68 { 69 if (function) 70 msg = std::string(function) + std::string("(): ") + msg; 71 } 72 }; 73 74 75 #endif // MIRAC_EXCEPTION_HPP 76 77