00001 /*************************************************************************** 00002 RM_Exception.h - description 00003 ------------------- 00004 begin : Tue Mar 5 2002 00005 copyright : (C) 2002 by Todd Davis 00006 email : todd.c.davis@intel.com 00007 ***************************************************************************/ 00008 00009 00010 /*M* 00011 BSD License 00012 00013 Copyright (c) 2002, Intel Corporation 00014 All rights reserved. 00015 00016 Redistribution and use in source and binary forms, with or without 00017 modification, are permitted provided that the following conditions are met: 00018 00019 a.. Redistributions of source code must retain the above copyright notice, 00020 this list of conditions and the following disclaimer. 00021 b.. Redistributions in binary form must reproduce the above copyright notice, 00022 this list of conditions and the following disclaimer in the documentation 00023 and/or other materials provided with the distribution. 00024 c.. Neither the name of Intel Corporation nor the names of its contributors 00025 may be used to endorse or promote products derived from this software 00026 without specific prior written permission. 00027 00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00029 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00030 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00031 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00033 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00035 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00037 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 00039 *M*/ 00040 00041 #ifndef __RM_Exception_h__ 00042 #define __RM_Exception_h__ 00043 00044 #include <exception> // for the exception 00045 #include <stdio.h> 00046 #include <string.h> 00047 #include <stdlib.h> 00048 /* Some exception */ 00049 00050 class Errno_Exception 00051 : public virtual std::exception 00052 { 00053 char *m_msg; 00054 int m_error; 00055 bool m_allocated; 00056 00057 public: 00058 00059 Errno_Exception (char * msg, 00060 int the_errno, 00061 bool allocated = true) 00062 : exception(), m_msg (msg), m_error (the_errno), 00063 m_allocated (allocated) 00064 { 00065 }; 00066 00067 Errno_Exception (const Errno_Exception &e) 00068 : exception(e), m_msg (0), m_error (e.m_error), 00069 m_allocated (e.m_allocated) 00070 { 00071 if (m_allocated) 00072 m_msg = strdup (e.m_msg); 00073 else 00074 m_msg = e.m_msg; 00075 }; 00076 00077 Errno_Exception ( int the_errno ) 00078 : exception(), m_msg (the_errno < sys_nerr ? (char *)(sys_errlist[the_errno]) : (char *)"unknown"), m_error (the_errno), 00079 m_allocated (false) 00080 { 00081 }; 00082 00083 virtual ~Errno_Exception (void) 00084 // throw() 00085 { 00086 if (m_msg && m_allocated) 00087 free (m_msg); 00088 }; 00089 00090 const char * what (void) const 00091 // throw() 00092 { 00093 return m_msg; 00094 }; 00095 00096 int error (void) const 00097 { 00098 return m_error; 00099 }; 00100 }; 00101 00102 #endif // __RM_Exception_h__