exceptions.hpp revision 1.1.1.3
1254721Semaste//
2254721Semaste// Automated Testing Framework (atf)
3353358Sdim//
4353358Sdim// Copyright (c) 2007 The NetBSD Foundation, Inc.
5353358Sdim// All rights reserved.
6254721Semaste//
7254721Semaste// Redistribution and use in source and binary forms, with or without
8254721Semaste// modification, are permitted provided that the following conditions
9254721Semaste// are met:
10353358Sdim// 1. Redistributions of source code must retain the above copyright
11254721Semaste//    notice, this list of conditions and the following disclaimer.
12254721Semaste// 2. Redistributions in binary form must reproduce the above copyright
13254721Semaste//    notice, this list of conditions and the following disclaimer in the
14254721Semaste//    documentation and/or other materials provided with the distribution.
15254721Semaste//
16254721Semaste// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17254721Semaste// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18254721Semaste// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19254721Semaste// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20321369Sdim// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21321369Sdim// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22254721Semaste// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23353358Sdim// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24353358Sdim// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25254721Semaste// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26254721Semaste// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27254721Semaste// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28360784Sdim//
29360784Sdim
30314564Sdim#if !defined(_ATF_CXX_EXCEPTIONS_HPP_)
31314564Sdim#define _ATF_CXX_EXCEPTIONS_HPP_
32314564Sdim
33254721Semaste#include <stdexcept>
34254721Semaste#include <string>
35314564Sdim
36314564Sdimextern "C" {
37254721Semastestruct atf_error;
38254721Semaste}
39314564Sdim
40314564Sdimnamespace atf {
41314564Sdim
42254721Semastetemplate< class T >
43254721Semasteclass not_found_error :
44314564Sdim    public std::runtime_error
45314564Sdim{
46254721Semaste    T m_value;
47254721Semaste
48360784Sdimpublic:
49360784Sdim    not_found_error(const std::string& message, const T& value) throw();
50254721Semaste
51254721Semaste    virtual ~not_found_error(void) throw();
52360784Sdim
53360784Sdim    const T& get_value(void) const throw();
54360784Sdim};
55254721Semaste
56360784Sdimtemplate< class T >
57360784Sdiminline
58314564Sdimnot_found_error< T >::not_found_error(const std::string& message,
59254721Semaste                                      const T& value)
60314564Sdim    throw() :
61254721Semaste    std::runtime_error(message),
62314564Sdim    m_value(value)
63314564Sdim{
64360784Sdim}
65360784Sdim
66314564Sdimtemplate< class T >
67341825Sdiminline
68341825Sdimnot_found_error< T >::~not_found_error(void)
69341825Sdim    throw()
70314564Sdim{
71314564Sdim}
72314564Sdim
73314564Sdimtemplate< class T >
74254721Semasteinline
75314564Sdimconst T&
76314564Sdimnot_found_error< T >::get_value(void)
77314564Sdim    const
78314564Sdim    throw()
79314564Sdim{
80314564Sdim    return m_value;
81254721Semaste}
82314564Sdim
83314564Sdimclass system_error : public std::runtime_error {
84314564Sdim    int m_sys_err;
85314564Sdim    mutable std::string m_message;
86314564Sdim
87314564Sdimpublic:
88254721Semaste    system_error(const std::string&, const std::string&, int);
89314564Sdim    ~system_error(void) throw();
90314564Sdim
91314564Sdim    int code(void) const throw();
92314564Sdim    const char* what(void) const throw();
93314564Sdim};
94314564Sdim
95314564Sdimvoid throw_atf_error(struct atf_error *);
96314564Sdim
97314564Sdim} // namespace atf
98314564Sdim
99314564Sdim#endif // !defined(_ATF_CXX_EXCEPTIONS_HPP_)
100314564Sdim