μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
exception.cpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30---------------------------------------------------------------------------
31*/
32
40
41
42#include <cstring>
43#include <iostream>
44#include <sstream>
45#include <stdlib.h>
46
47
48namespace uhal
49{
50 namespace exception
51 {
52
54 std::exception (),
55 mString ( ( char* ) malloc ( 65536 ) )
56 {
57 gettimeofday ( &mTime, NULL );
58 mString[0] = '\0'; //malloc is not required to initialize to null, so do it manually, just in case
59 }
60
61
62 exception::exception ( const exception& aExc ) :
63 std::exception (),
64 mTime ( aExc.mTime ),
65 mString ( ( char* ) malloc ( 65536 ) )
66 {
67 strcpy ( mString , aExc.mString );
68 }
69
71 {
72 strcpy ( mString , aExc.mString );
73 mTime = aExc.mTime;
74 return *this;
75 }
76
77 exception::~exception() throw()
78 {
79 if ( mString )
80 {
81 free ( mString );
82 mString = NULL;
83 }
84 }
85
86
87 const char* exception::what() const throw()
88 {
89
90 if ( strlen ( mString ) )
91 {
92 return mString;
93 }
94 else
95 {
96 std::stringstream lStr;
97 lStr << description() << " (no additional info)";
98 std::string lString ( lStr.str() );
99 strncpy ( mString , lString.c_str() , 65536 );
100 return mString;
101 }
102 }
103
104 void exception::append ( const char* aCStr ) throw()
105 {
106 strncat ( mString, aCStr , 65536-strlen ( mString ) );
107 }
108
109 }
110}
111
112
113
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
exception()=default
object & operator=(const object &other)
Definition: pytypes.h:289
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
Definition: exception.hpp:71
timeval mTime
The time at which the exception was thrown.
Definition: exception.hpp:113
char * mString
Memory into which message is added by calls to append.
Definition: exception.hpp:116