exceptions.hpp revision 240116
1240116Smarcel//
2240116Smarcel// Automated Testing Framework (atf)
3240116Smarcel//
4240116Smarcel// Copyright (c) 2007 The NetBSD Foundation, Inc.
5240116Smarcel// All rights reserved.
6240116Smarcel//
7240116Smarcel// Redistribution and use in source and binary forms, with or without
8240116Smarcel// modification, are permitted provided that the following conditions
9240116Smarcel// are met:
10240116Smarcel// 1. Redistributions of source code must retain the above copyright
11240116Smarcel//    notice, this list of conditions and the following disclaimer.
12240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright
13240116Smarcel//    notice, this list of conditions and the following disclaimer in the
14240116Smarcel//    documentation and/or other materials provided with the distribution.
15240116Smarcel//
16240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28240116Smarcel//
29240116Smarcel
30240116Smarcel#if !defined(_ATF_CXX_EXCEPTIONS_HPP_)
31240116Smarcel#define _ATF_CXX_EXCEPTIONS_HPP_
32240116Smarcel
33240116Smarcel#include <stdexcept>
34240116Smarcel#include <string>
35240116Smarcel
36240116Smarcelextern "C" {
37240116Smarcelstruct atf_error;
38240116Smarcel}
39240116Smarcel
40240116Smarcelnamespace atf {
41240116Smarcel
42240116Smarceltemplate< class T >
43240116Smarcelclass not_found_error :
44240116Smarcel    public std::runtime_error
45240116Smarcel{
46240116Smarcel    T m_value;
47240116Smarcel
48240116Smarcelpublic:
49240116Smarcel    not_found_error(const std::string& message, const T& value) throw();
50240116Smarcel
51240116Smarcel    virtual ~not_found_error(void) throw();
52240116Smarcel
53240116Smarcel    const T& get_value(void) const throw();
54240116Smarcel};
55240116Smarcel
56240116Smarceltemplate< class T >
57240116Smarcelinline
58240116Smarcelnot_found_error< T >::not_found_error(const std::string& message,
59240116Smarcel                                      const T& value)
60240116Smarcel    throw() :
61240116Smarcel    std::runtime_error(message),
62240116Smarcel    m_value(value)
63240116Smarcel{
64240116Smarcel}
65240116Smarcel
66240116Smarceltemplate< class T >
67240116Smarcelinline
68240116Smarcelnot_found_error< T >::~not_found_error(void)
69240116Smarcel    throw()
70240116Smarcel{
71240116Smarcel}
72240116Smarcel
73240116Smarceltemplate< class T >
74240116Smarcelinline
75240116Smarcelconst T&
76240116Smarcelnot_found_error< T >::get_value(void)
77240116Smarcel    const
78240116Smarcel    throw()
79240116Smarcel{
80240116Smarcel    return m_value;
81240116Smarcel}
82240116Smarcel
83240116Smarcelclass system_error : public std::runtime_error {
84240116Smarcel    int m_sys_err;
85240116Smarcel    mutable std::string m_message;
86240116Smarcel
87240116Smarcelpublic:
88240116Smarcel    system_error(const std::string&, const std::string&, int);
89240116Smarcel    ~system_error(void) throw();
90240116Smarcel
91240116Smarcel    int code(void) const throw();
92240116Smarcel    const char* what(void) const throw();
93240116Smarcel};
94240116Smarcel
95240116Smarcelvoid throw_atf_error(struct atf_error *);
96240116Smarcel
97240116Smarcel} // namespace atf
98240116Smarcel
99240116Smarcel#endif // !defined(_ATF_CXX_EXCEPTIONS_HPP_)
100