Exception.h

00001 /*
00002  * exception.h - environmetal, or usage error Exception classes.
00003  *
00004  * This file is part of the Rulbus Device Class Library (RDCL).
00005  *
00006  * Copyright (C) 2003-2004, Leiden University.
00007  *
00008  * This library is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * The library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with mngdriver; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * $Id: Exception.h 2 2004-10-12 11:54:15Z moene $
00023  */
00024 
00025 #ifndef __EXCEPTION_H
00026 #define __EXCEPTION_H
00027 
00028 #ifndef __COMMON_H
00029    #include "Common.h"
00030 #endif
00031 
00032 #include <stdexcept>            // for standard exceptions
00033 
00034 #if __BCPLUSPLUS__ < 0x0560
00035    using std::__threadid;       // needed for Borland C++ 5.5.1; _stddef.h apparently errs
00036 #endif
00037 
00038 namespace Rulbus
00039 {
00040    DECLARE_CLASS( RulbusError          );       
00041    DECLARE_CLASS( RulbusScanError      );       
00042    DECLARE_CLASS( RulbusParseError     );       
00043    DECLARE_CLASS( RulbusConfigError    );       
00044    DECLARE_CLASS( RulbusInterfaceError );       
00045    DECLARE_CLASS( RulbusOpenError      );       
00046    DECLARE_CLASS( RulbusCloseError     );       
00047    DECLARE_CLASS( RulbusHandleError    );       
00048    DECLARE_CLASS( RulbusAddressError   );       
00049    DECLARE_CLASS( RulbusRangeError     );       
00050    DECLARE_CLASS( RulbusContextError   );       
00051    DECLARE_CLASS( RulbusTimeoutError   );       
00052 
00057    inline CharCptr to_cstr( const String& s )
00058    {
00059       return s.c_str();
00060    }
00061 
00111    class RulbusError : public StdException
00112    {
00113    public:
00116 
00118       RulbusError() { tid = _threadid; theError = *this; }
00119 
00121       RulbusError( CharCptr fmt ... );
00122 
00123       // RulbusError(CharCptr fmt, va_list ap );
00124 
00126       RulbusError( StringCref string );
00127 
00129       RulbusError( StdExceptionCref e ) { msg = e.what(); tid = _threadid; theError = *this; }
00130 
00132       RulbusError( RulbusErrorCref e ) { msg = e.msg; tid = e.tid; theError = *this; }
00133 
00135       virtual ~RulbusError() { ; }
00136 
00140 
00142       virtual  CharCptr      what   () const { return to_cstr( msg ); }
00143 
00145       virtual  unsigned long lasttid() const { return tid;         }
00146 
00147       static   bool     getLastError( char *msg, int maxlen );
00148 
00150 
00151    private:
00152       String msg;                       
00153       unsigned long tid;                
00154 
00155       static RulbusError theError;      
00156    };
00157 
00166    class RulbusScanError : public RulbusError
00167    {
00168    public:
00170       RulbusScanError( StringCref msg ):
00171          RulbusError( msg ) { ; }
00172    };
00173 
00182    class RulbusParseError : public RulbusError
00183    {
00184    public:
00186       RulbusParseError( StringCref msg ):
00187          RulbusError( msg ) { ; }
00188    };
00189 
00199    class RulbusConfigError : public RulbusError
00200    {
00201    public:
00203       RulbusConfigError( StringCref msg ):
00204          RulbusError( to_cstr( msg ) ) { ; }
00205    };
00206 
00214    class RulbusInterfaceError : public RulbusError
00215    {
00216    public:
00218       RulbusInterfaceError( StringCref msg ):
00219          RulbusError( to_cstr( msg )  ) { ; }
00220    };
00221 
00229    class RulbusOpenError : public RulbusError
00230    {
00231    public:
00233       RulbusOpenError( StringCref submsg ):
00234          RulbusError( "cannot open rulbus device: %s", to_cstr( submsg ) ) { ; }
00235 
00237       RulbusOpenError( StringCref name, int rack, int addr ):
00238          RulbusError( "cannot open rulbus device '%s' at [%d:0x%02X]", to_cstr( name ), rack, addr ) { ; }
00239    };
00240 
00248    class RulbusCloseError : public RulbusError
00249    {
00250    public:
00252       RulbusCloseError( int handle ):
00253          RulbusError("cannot close rulbus device with handle '%d'", handle ) { ; }
00254    };
00255 
00263    class RulbusHandleError : public RulbusError
00264    {
00265    public:
00267       RulbusHandleError( int handle ):
00268          RulbusError("invalid handle '%d'", handle ) { ; }
00269    };
00270 
00278    class RulbusAddressError : public RulbusError
00279    {
00280    public:
00282       RulbusAddressError( StringCref name, int rack, int addr ):
00283          RulbusError("address violation, device '%s', address [%d:0x%02X]", to_cstr( name ), rack, addr ) { ; }
00284    };
00285 
00293    class RulbusDataError : public RulbusError
00294    {
00295    public:
00297       RulbusDataError( StringCref name, int rack, int addr, int data ):
00298          RulbusError("data violation, device '%s', address [%d:0x%02X], data [0x%02X]", to_cstr( name ), rack, addr, data ) { ; }
00299    };
00300 
00308    class RulbusRangeError : public RulbusError
00309    {
00310    public:
00312       RulbusRangeError( ):
00313          RulbusError() { ; }
00314 
00316       RulbusRangeError( StringCref name, StringCref parameter, int data, int min, int max ):
00317          RulbusError("device '%s', range error: %s %d not in [%d..%d]", to_cstr( name ), to_cstr( parameter ), data, min, max ) { ; }
00318 
00320       RulbusRangeError( StringCref name, StringCref parameter, long data, long min, long max ):
00321          RulbusError("device '%s', range error: %s %ld not in [%ld..%ld]", to_cstr( name ), to_cstr( parameter ), data, min, max ) { ; }
00322 
00324       RulbusRangeError( StringCref name, StringCref parameter, Real data, Real min, Real max ):
00325          RulbusError("device '%s', range error: %s %g not in [%g..%g]", to_cstr( name ), to_cstr( parameter ), data, min, max ) { ; }
00326 
00328       RulbusRangeError( StringCref name, StringCref parameter, StringCref data, StringCref set ):
00329          RulbusError("device '%s', range error: %s %s not in [%s]", to_cstr( name ), to_cstr( parameter ), to_cstr( data ), to_cstr( set ) ) { ; }
00330    };
00331 
00339    class RulbusContextError : public RulbusError
00340    {
00341    public:
00343       RulbusContextError( StringCref name, StringCref msg ):
00344          RulbusError("device '%s', context error: %s", to_cstr( name ), to_cstr( msg ) ) { ; }
00345    };
00346 
00354    class RulbusTimeoutError : public RulbusError
00355    {
00356    public:
00358       RulbusTimeoutError( ):
00359          RulbusError() { ; }
00360 
00362       RulbusTimeoutError( StringCref name, StringCref msg ):
00363          RulbusError("device '%s', timeout: %s", to_cstr( name ), to_cstr( msg ) ) { ; }
00364    };
00365 
00368 }       // namespace Rulbus
00369 
00370 #endif  // __EXCEPTION_H
00371 
00372 /*
00373  * end of file
00374  */

Generated on Tue Oct 12 14:11:57 2004 for Rulbus Device Class Library for Microsoft Windows by doxygen 1.3.4