-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.cc
More file actions
60 lines (39 loc) · 1.64 KB
/
exception.cc
File metadata and controls
60 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Time-stamp: <2018-05-31 15:24:04 daniel>
//
// exception.cc: Exception class used with the taurus library
//
// Time-stamp: <>
// Requried header files
//------------------------------------------------------------------------------
#include <cerrno> // error number
#include <cstring> // strerror_r
#include "exception.hh" // taurus::exception
#include <iostream>
// NS Short-cuts
//-----------------------------------------------------------------------------
//using namespace taurus; // library NS shortcut
// Class constructor
//-----------------------------------------------------------------------------
taurus::exception::exception( int err_num )
: std::runtime_error( "" ),
message_( ) {
std::cout << "constructor" << std::endl;
char buffer[ exception::length ];
auto cstr = strerror_r( err_num, buffer, exception::length );
if ( cstr == 0x0 ) throw runtime_error( "Call to strerror_r failed!" );
std::cout << "cstr: " << cstr[ 0 ] << std::endl;
message_.assign( cstr ); // save the message
std::cout << "err_num: " << err_num << " -- message_: " << message_ << std::endl;
}; // end constructor
// Copy constructor
//-----------------------------------------------------------------------------
taurus::exception::exception( const taurus::exception& except )
: std::runtime_error( nullptr ),
message_( except.message_ ) {
std::cout << "DB: exception copy constructor" << std::endl;
}; // end copy construtor
// Return the error message
//-----------------------------------------------------------------------------
const char* taurus::exception::what() const noexcept {
return message_.c_str();
}; // end what