Exception.hpp 2.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/******************************************************************************
 *                      Exception.hpp
 *
 * 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.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/
Eric Cano's avatar
Eric Cano committed
24
25
26
27
28

#pragma once
#include <exception>
#include <string>

29
30
namespace castor {
namespace tape {
31
32
33
34
35
36
37
38
39
40
41
  
  namespace Exceptions {
    class Backtrace {
    public:
      Backtrace();
      operator std::string() const { return m_trace; }
    private:
      std::string m_trace;
    };
  }
  
Eric Cano's avatar
Eric Cano committed
42
43
  class Exception: public std::exception {
  public:
44
    Exception(const std::string& what) { setWhat(what); }
Eric Cano's avatar
Eric Cano committed
45
    virtual ~Exception() throw() {};
46
    virtual const char * what() const throw();
47
    virtual const char * shortWhat() const throw();
48
    Exceptions::Backtrace backtrace;
Eric Cano's avatar
Eric Cano committed
49
  protected:
50
51
    void setWhat(const std::string &w);
  private:
Eric Cano's avatar
Eric Cano committed
52
    std::string m_what;
53
    std::string m_shortWhat;
Eric Cano's avatar
Eric Cano committed
54
55
56
  };

  namespace Exceptions {
57
    class Errnum: public Exception {
Eric Cano's avatar
Eric Cano committed
58
59
60
61
62
    public:
      Errnum(std::string what = "");
      virtual ~Errnum() throw() {};
      int ErrorNumber() { return m_errnum; }
      std::string strError() { return m_strerror; }
63
64
      /* We rely on base version:
       *  virtual const char * what() const throw() */
Eric Cano's avatar
Eric Cano committed
65
66
67
68
    protected:
      int m_errnum;
      std::string m_strerror;
    };
69
    
70
71
    class InvalidArgument: public Exception {
    public: InvalidArgument(std::string what = ""): Exception(what) {};
72
    };
Eric Cano's avatar
Eric Cano committed
73
  }
74
75
} //namespace tape
} //namespace castor