exceptions.hpp revision 1.1
190075Sobrien//
290075Sobrien// Automated Testing Framework (atf)
3132718Skan//
4117395Skan// Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
590075Sobrien// All rights reserved.
6132718Skan//
790075Sobrien// Redistribution and use in source and binary forms, with or without
8132718Skan// modification, are permitted provided that the following conditions
9132718Skan// are met:
10132718Skan// 1. Redistributions of source code must retain the above copyright
11132718Skan//    notice, this list of conditions and the following disclaimer.
1290075Sobrien// 2. Redistributions in binary form must reproduce the above copyright
13132718Skan//    notice, this list of conditions and the following disclaimer in the
14132718Skan//    documentation and/or other materials provided with the distribution.
15132718Skan//
16132718Skan// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1790075Sobrien// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18132718Skan// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19132718Skan// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20169689Skan// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21169689Skan// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2290075Sobrien// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23132718Skan// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24117395Skan// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25117395Skan// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26117395Skan// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27117395Skan// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28117395Skan//
29117395Skan
30117395Skan#if !defined(_ATF_CXX_EXCEPTIONS_HPP_)
31117395Skan#define _ATF_CXX_EXCEPTIONS_HPP_
32117395Skan
3390075Sobrien#include <stdexcept>
34117395Skan
35117395Skanextern "C" {
3690075Sobrienstruct atf_error;
37132718Skan}
38117395Skan
39117395Skannamespace atf {
40117395Skan
41117395Skantemplate< class T >
42117395Skanclass not_found_error :
43117395Skan    public std::runtime_error
44117395Skan{
45117395Skan    T m_value;
46117395Skan
47117395Skanpublic:
48117395Skan    not_found_error(const std::string& message, const T& value) throw();
49117395Skan
50117395Skan    virtual ~not_found_error(void) throw();
51117395Skan
52117395Skan    const T& get_value(void) const throw();
5390075Sobrien};
54117395Skan
5590075Sobrientemplate< class T >
56132718Skaninline
57117395Skannot_found_error< T >::not_found_error(const std::string& message,
5890075Sobrien                                      const T& value)
59132718Skan    throw() :
60117395Skan    std::runtime_error(message),
6190075Sobrien    m_value(value)
62117395Skan{
63117395Skan}
6490075Sobrien
65132718Skantemplate< class T >
66117395Skaninline
6790075Sobriennot_found_error< T >::~not_found_error(void)
68132718Skan    throw()
69117395Skan{
70117395Skan}
71117395Skan
7290075Sobrientemplate< class T >
73117395Skaninline
7490075Sobrienconst T&
75132718Skannot_found_error< T >::get_value(void)
76117395Skan    const
77117395Skan    throw()
78132718Skan{
79117395Skan    return m_value;
80117395Skan}
81117395Skan
82132718Skanclass system_error : public std::runtime_error {
83117395Skan    int m_sys_err;
84117395Skan    mutable std::string m_message;
85132718Skan
86117395Skanpublic:
87117395Skan    system_error(const std::string&, const std::string&, int);
88117395Skan    ~system_error(void) throw();
89117395Skan
90117395Skan    int code(void) const throw();
91117395Skan    const char* what(void) const throw();
92132718Skan};
93117395Skan
94void throw_atf_error(struct atf_error *);
95
96} // namespace atf
97
98#endif // !defined(_ATF_CXX_EXCEPTIONS_HPP_)
99