Exception.hpp 2.26 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
29

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

namespace Tape {
30
31
32
33
34
35
36
37
38
39
40
  
  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
41
42
  class Exception: public std::exception {
  public:
43
    Exception(const std::string& what) { setWhat(what); }
Eric Cano's avatar
Eric Cano committed
44
    virtual ~Exception() throw() {};
45
    virtual const char * what() const throw();
46
    virtual const char * shortWhat() const throw();
47
    Tape::Exceptions::Backtrace backtrace;
Eric Cano's avatar
Eric Cano committed
48
  protected:
49
50
    void setWhat(const std::string &w);
  private:
Eric Cano's avatar
Eric Cano committed
51
    std::string m_what;
52
    std::string m_shortWhat;
Eric Cano's avatar
Eric Cano committed
53
54
55
56
57
58
59
60
61
  };

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