nidas v1.2.3
Exception.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_UTIL_EXCEPTION_H
28#define NIDAS_UTIL_EXCEPTION_H
29
30#include <string>
31#include <errno.h>
32
33namespace nidas { namespace util {
34
35class Exception : public std::exception {
36
37protected:
38 std::string _what;
39 int _errno;
40
41 Exception(const std::string& type, const std::string& n, const std::string& m):
42 std::exception(), _what(type + ": " + n + ": " + m),_errno(0) {}
43
44 Exception(const std::string& type, const std::string& n, int ierr):
45 std::exception(), _what(type + ": " + n + ": " + errnoToString(ierr)),_errno(ierr) {}
46
47public:
48
54 Exception(const std::string& n, const std::string& m):
55 std::exception(), _what("Exception: " + n + ": " + m),_errno(0) {}
56
62 Exception(const std::string& m, int ierr):
63 std::exception(),_what("Exception: " + m + ": " + errnoToString(ierr)),_errno(ierr) {}
64
65 Exception(const std::string& m):
66 std::exception(),_what(m),_errno(0) {}
67
72 std::exception(e),_what(e._what),_errno(e._errno) {}
73
75 {
76 std::exception::operator=(e);
77 _what = e._what;
78 _errno = e._errno;
79 return *this;
80 }
81
82 virtual ~Exception() throw() {}
83
84 virtual Exception* clone() const {
85 return new Exception(*this);
86 }
87
88 virtual int getErrno() const { return _errno; }
89
94 static std::string errnoToString(int err);
95
96 virtual std::string toString() const throw() { return _what; }
97
98 virtual const char* what() const throw() { return _what.c_str(); }
99};
100
101}} // namespace nidas::util
102
103#endif
#define err(format, arg...)
Definition ck_lams.cc:55
Definition Exception.h:35
virtual Exception * clone() const
Definition Exception.h:84
virtual ~Exception()
Definition Exception.h:82
static std::string errnoToString(int err)
Return string description of an errno (from errno.h).
Definition Exception.cc:35
Exception & operator=(const Exception &e)
Definition Exception.h:74
virtual const char * what() const
Definition Exception.h:98
std::string _what
Definition Exception.h:38
Exception(const std::string &m, int ierr)
Constructor for an exception.
Definition Exception.h:62
int _errno
Definition Exception.h:39
Exception(const std::string &type, const std::string &n, int ierr)
Definition Exception.h:44
Exception(const std::string &m)
Definition Exception.h:65
Exception(const std::string &type, const std::string &n, const std::string &m)
Definition Exception.h:41
Exception(const std::string &n, const std::string &m)
Constructor for an exception.
Definition Exception.h:54
virtual std::string toString() const
Definition Exception.h:96
virtual int getErrno() const
Definition Exception.h:88
Exception(const Exception &e)
Copy constructor.
Definition Exception.h:71
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31