diff --git a/include/boost/exception/all.hpp b/include/boost/exception/all.hpp new file mode 100644 index 0000000..c5c677e --- /dev/null +++ b/include/boost/exception/all.hpp @@ -0,0 +1,26 @@ +//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_316FDA946C0D11DEA9CBAE5255D89593 +#define UUID_316FDA946C0D11DEA9CBAE5255D89593 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef BOOST_NO_EXCEPTIONS +#include +#endif + +#endif diff --git a/include/boost/exception/errinfo_api_function.hpp b/include/boost/exception/errinfo_api_function.hpp new file mode 100644 index 0000000..481c613 --- /dev/null +++ b/include/boost/exception/errinfo_api_function.hpp @@ -0,0 +1,22 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_DDFBB4546C1211DEA4659E9055D89593 +#define UUID_DDFBB4546C1211DEA4659E9055D89593 + +#include "boost/exception/error_info.hpp" + +namespace +boost + { + //Usage hint: + //if( api_function(....)!=0 ) + // BOOST_THROW_EXCEPTION( + // failure() << + // errinfo_api_function("api_function") ); + typedef error_info errinfo_api_function; + } + +#endif diff --git a/include/boost/exception/errinfo_at_line.hpp b/include/boost/exception/errinfo_at_line.hpp new file mode 100644 index 0000000..cbd5cce --- /dev/null +++ b/include/boost/exception/errinfo_at_line.hpp @@ -0,0 +1,18 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_E7255CE26C1211DE85800C9155D89593 +#define UUID_E7255CE26C1211DE85800C9155D89593 + +namespace +boost + { + template class error_info; + + //Use with parsing errors exceptions, for example in a XML file parser. + typedef error_info errinfo_at_line; + } + +#endif diff --git a/include/boost/exception/errinfo_errno.hpp b/include/boost/exception/errinfo_errno.hpp new file mode 100644 index 0000000..f3ee8d2 --- /dev/null +++ b/include/boost/exception/errinfo_errno.hpp @@ -0,0 +1,34 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_F0EE17BE6C1211DE87FF459155D89593 +#define UUID_F0EE17BE6C1211DE87FF459155D89593 + +#include "boost/exception/info.hpp" +#include + +namespace +boost + { + typedef error_info errinfo_errno; + + //Usage hint: + //if( c_function(....)!=0 ) + // BOOST_THROW_EXCEPTION( + // failure() << + // errinfo_errno(errno) << + // errinfo_api_function("c_function") ); + inline + std::string + to_string( errinfo_errno const & e ) + { + std::ostringstream tmp; + int v=e.value(); + tmp << v << ", \"" << strerror(v) << "\""; + return tmp.str(); + } + } + +#endif diff --git a/include/boost/exception/errinfo_file_handle.hpp b/include/boost/exception/errinfo_file_handle.hpp new file mode 100644 index 0000000..8e6cff8 --- /dev/null +++ b/include/boost/exception/errinfo_file_handle.hpp @@ -0,0 +1,20 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_F79E6EE26C1211DEB26E929155D89593 +#define UUID_F79E6EE26C1211DEB26E929155D89593 + +#include + +namespace +boost + { + template class weak_ptr; + template class error_info; + + typedef error_info > errinfo_file_handle; + } + +#endif diff --git a/include/boost/exception/errinfo_file_name.hpp b/include/boost/exception/errinfo_file_name.hpp new file mode 100644 index 0000000..d3cce4d --- /dev/null +++ b/include/boost/exception/errinfo_file_name.hpp @@ -0,0 +1,26 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_FEE5120A6C1211DE94E8BC9155D89593 +#define UUID_FEE5120A6C1211DE94E8BC9155D89593 + +#include + +namespace +boost + { + template class error_info; + + //Usage hint: + //FILE * f=fopen(name,mode); + //if( !f ) + // BOOST_THROW_EXCEPTION( + // file_open_error() << + // errinfo_file_name(name) << + // errinfo_file_open_mode(mode) ); + typedef error_info errinfo_file_name; + } + +#endif diff --git a/include/boost/exception/errinfo_file_open_mode.hpp b/include/boost/exception/errinfo_file_open_mode.hpp new file mode 100644 index 0000000..f4fba0d --- /dev/null +++ b/include/boost/exception/errinfo_file_open_mode.hpp @@ -0,0 +1,26 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_056F1F266C1311DE8E74299255D89593 +#define UUID_056F1F266C1311DE8E74299255D89593 + +#include + +namespace +boost + { + template class error_info; + + //Usage hint: + //FILE * f=fopen(name,mode); + //if( !f ) + // BOOST_THROW_EXCEPTION( + // file_open_error() << + // errinfo_file_name(name) << + // errinfo_file_open_mode(mode) ); + typedef error_info errinfo_file_open_mode; + } + +#endif diff --git a/include/boost/exception/errinfo_type_info_name.hpp b/include/boost/exception/errinfo_type_info_name.hpp new file mode 100644 index 0000000..0b060e2 --- /dev/null +++ b/include/boost/exception/errinfo_type_info_name.hpp @@ -0,0 +1,23 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef UUID_0E11109E6C1311DEB7EA649255D89593 +#define UUID_0E11109E6C1311DEB7EA649255D89593 + +#include + +namespace +boost + { + template class error_info; + + //Usage hint: + //BOOST_THROW_EXCEPTION( + // bad_type() << + // errinfo_type_info_name(typeid(x).name()) ); + typedef error_info errinfo_type_info_name; + } + +#endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 894a916..23d38e7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -35,6 +35,7 @@ run diagnostic_information_test.cpp ; run refcount_ptr_test.cpp ; run current_exception_cast_test.cpp ; run no_exceptions_test.cpp : : : off ; +run errinfos_test.cpp ; compile-fail exception_fail.cpp ; compile-fail throw_exception_fail.cpp ; @@ -49,4 +50,12 @@ compile info_hpp_test.cpp ; compile info_tuple_hpp_test.cpp ; compile to_string_hpp_test.cpp ; compile to_string_stub_hpp_test.cpp ; +compile all_hpp_test.cpp ; compile current_exception_cast_hpp_test.cpp ; +compile errinfo_api_function_hpp_test.cpp ; +compile errinfo_at_line_hpp_test.cpp ; +compile errinfo_errno_hpp_test.cpp ; +compile errinfo_file_handle_hpp_test.cpp ; +compile errinfo_file_name_hpp_test.cpp ; +compile errinfo_file_open_mode_hpp_test.cpp ; +compile errinfo_type_info_name_hpp_test.cpp ; diff --git a/test/all_hpp_test.cpp b/test/all_hpp_test.cpp new file mode 100644 index 0000000..0e3fe58 --- /dev/null +++ b/test/all_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_api_function_hpp_test.cpp b/test/errinfo_api_function_hpp_test.cpp new file mode 100644 index 0000000..fcb9234 --- /dev/null +++ b/test/errinfo_api_function_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_at_line_hpp_test.cpp b/test/errinfo_at_line_hpp_test.cpp new file mode 100644 index 0000000..cf13e30 --- /dev/null +++ b/test/errinfo_at_line_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_errno_hpp_test.cpp b/test/errinfo_errno_hpp_test.cpp new file mode 100644 index 0000000..6bd627e --- /dev/null +++ b/test/errinfo_errno_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_file_handle_hpp_test.cpp b/test/errinfo_file_handle_hpp_test.cpp new file mode 100644 index 0000000..8419749 --- /dev/null +++ b/test/errinfo_file_handle_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_file_name_hpp_test.cpp b/test/errinfo_file_name_hpp_test.cpp new file mode 100644 index 0000000..2018d6b --- /dev/null +++ b/test/errinfo_file_name_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_file_open_mode_hpp_test.cpp b/test/errinfo_file_open_mode_hpp_test.cpp new file mode 100644 index 0000000..4d6ebd3 --- /dev/null +++ b/test/errinfo_file_open_mode_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfo_type_info_name_hpp_test.cpp b/test/errinfo_type_info_name_hpp_test.cpp new file mode 100644 index 0000000..20888ef --- /dev/null +++ b/test/errinfo_type_info_name_hpp_test.cpp @@ -0,0 +1,7 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include diff --git a/test/errinfos_test.cpp b/test/errinfos_test.cpp new file mode 100644 index 0000000..a496e87 --- /dev/null +++ b/test/errinfos_test.cpp @@ -0,0 +1,61 @@ +//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. + +//Distributed under the Boost Software License, Version 1.0. (See accompanying +//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct +test_exception: + virtual boost::exception, + virtual std::exception + { + }; + +int +main() + { + using namespace boost; + try + { + BOOST_THROW_EXCEPTION( + test_exception() << + errinfo_api_function("failed_api_function") << + errinfo_at_line(42) << + errinfo_errno(errno) << + errinfo_file_handle(weak_ptr()) << + errinfo_file_name("filename.txt") << + errinfo_file_open_mode("rb") << + errinfo_type_info_name(typeid(int).name()) ); + BOOST_TEST(false); + } + catch( + exception & e ) + { + BOOST_TEST(get_error_info(e) && *get_error_info(e)==std::string("failed_api_function")); + BOOST_TEST(get_error_info(e) && *get_error_info(e)==42); + BOOST_TEST(get_error_info(e) && *get_error_info(e)==0); + BOOST_TEST(get_error_info(e) && get_error_info(e)->expired()); + BOOST_TEST(get_error_info(e) && *get_error_info(e)=="filename.txt"); + BOOST_TEST(get_error_info(e) && *get_error_info(e)=="rb"); + BOOST_TEST(get_error_info(e) && *get_error_info(e)==typeid(int).name()); + } + catch( + ... ) + { + BOOST_TEST(false); + } + return boost::report_errors(); + }