Exception.cpp 3.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 * 
 *
22
 * @author Castor Dev team, castor-dev@cern.ch
23
 *****************************************************************************/
24
#define _XOPEN_SOURCE 600
25
26

#include "castor/exception/Exception.hpp"
27
#include "serrno.h"
28

29
30
31
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
32
33
castor::exception::Exception::Exception(int se, std::string context, bool embedBacktrace) : 
  m_message(context), m_serrno(se), m_backtrace(!embedBacktrace) {}
34
35
36
37

//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
38
39
castor::exception::Exception::Exception(std::string context, bool embedBacktrace) : 
  m_message(context), m_serrno(SEINTERNAL), m_backtrace(!embedBacktrace) {}
40

41
42
43
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
44
45
46
47
48
castor::exception::Exception::Exception(
  const castor::exception::Exception& rhs):
  std::exception() {
  m_serrno = rhs.m_serrno;
  m_message << rhs.m_message.str();
49
  m_backtrace = rhs.m_backtrace;
Giuseppe Lo Presti's avatar
Giuseppe Lo Presti committed
50
}
51

52
53

//------------------------------------------------------------------------------
54
// assignment operator
55
//------------------------------------------------------------------------------
56
57
58
59
castor::exception::Exception& castor::exception::Exception::operator=(
  const castor::exception::Exception &rhs) {
  m_serrno = rhs.m_serrno;
  m_message << rhs.m_message.str();
60
61
62
  return *this;
}

63
64
65
//------------------------------------------------------------------------------
// what operator
//------------------------------------------------------------------------------
66
67
const char * castor::exception::Exception::what() const throw () {
  m_what = getMessageValue();
68
69
70
71
72
  m_what += "\n";
  m_what += (std::string) m_backtrace;
  return m_what.c_str();
}

73
74
75
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
76
castor::exception::Exception::~Exception() throw()  {}
77
78
79
80
81
//------------------------------------------------------------------------------
// setWhat
//------------------------------------------------------------------------------
void castor::exception::Exception::setWhat(const std::string& what) {
  getMessage() << what;
82
83
}