1 /* 2 * Portable Agile C++ Classes (PACC) 3 * Copyright (C) 2001-2003 by Marc Parizeau 4 * http://manitou.gel.ulaval.ca/~parizeau/PACC 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 * Contact: 21 * Laboratoire de Vision et Systemes Numeriques 22 * Departement de genie electrique et de genie informatique 23 * Universite Laval, Quebec, Canada, G1K 7P4 24 * http://vision.gel.ulaval.ca 25 * 26 */ 27 28 /*! 29 * \file PACC/Threading/Exception.hpp 30 * \brief Class definition for the threading exception. 31 * \author Marc Parizeau, Laboratoire de vision et systèmes numériques, Université Laval 32 * $Revision: 1.5.2.1 $ 33 * $Date: 2007/09/10 18:24:10 $ 34 */ 35 36 #ifndef PACC_Threading_Exception_hpp_ 37 #define PACC_Threading_Exception_hpp_ 38 39 #include <stdexcept> 40 #include <string> 41 42 namespace PACC { 43 44 using namespace std; 45 46 namespace Threading { 47 48 //! Supported Multithread error codes. 49 enum Error { 50 eMutexNotOwned, //!< Mutex not own by calling thread 51 eWouldDeadLock, //!< Operation would produce a dead lock. 52 eRunning, //!< Thread is already running 53 eOtherError //!< Any other OS specific error. 54 }; 55 56 /*! 57 \brief Multithread exception. 58 \author Marc Parizeau, Laboratoire de vision et systèmes numériques, Université Laval 59 \ingroup Threading 60 61 This class encapsulates most interesting runtime errors that can happen while using multithreading operations. 62 */ 63 class Exception : public runtime_error { 64 public: 65 //! Construct with native error code. Exception(int inNativeCode,const string & inMessage)66 explicit Exception(int inNativeCode, const string& inMessage) 67 : runtime_error(inMessage), mNativeCode(inNativeCode) {mCode = convertNativeError(inNativeCode);} 68 //! Construct with multithreading error code. Exception(Error inCode,const string & inMessage)69 explicit Exception(Error inCode, const string& inMessage) : runtime_error(inMessage), mCode(inCode) {mNativeCode = 0;} 70 71 static Error convertNativeError(int inError); 72 73 //! Return error code. getErrorCode()74 int getErrorCode() {return mCode;} 75 76 string getMessage() const throw(); 77 78 protected: 79 Error mCode; //!< Portable error code. 80 int mNativeCode; //!< Native error code. 81 82 }; 83 84 } // end of Threading namespace 85 86 } // end of PACC namespace 87 88 #endif // PACC_Threading_Exception_hpp_ 89