diff options
author | Roger Leigh <rleigh@debian.org> | 2006-07-12 15:28:01 +0000 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2006-07-12 15:28:01 +0000 |
commit | 0cd0dfc91aceacc4a7ffe4518064ba43dbffa4b1 (patch) | |
tree | 6968cf2e6421fc9d1cd68e81d8a5e461df88609b /sbuild/sbuild-custom-error.h | |
parent | cf6ce41a8d79ac7d0e867dd23302bc38cd3415ee (diff) | |
download | schroot-0cd0dfc91aceacc4a7ffe4518064ba43dbffa4b1.tar.gz |
* sbuild/sbuild-chroot-config.cc
(load_data): Use new error contructor.
* sbuild/sbuild-session.cc
(wait_for_child): Use new error contructor.
* sbuild/sbuild-custom-error.tcc
(format_error): Replace all overloaded functions with two
variants, one for an error_type enum, one for an exception (for
rethrowing an exception of a different type).
* sbuild/sbuild-custom-error.h: Add new custom_error<>::null
class, used to represent an absent context or detail item in an
error. Add two new constructors for rethrowing exceptions.
Diffstat (limited to 'sbuild/sbuild-custom-error.h')
-rw-r--r-- | sbuild/sbuild-custom-error.h | 121 |
1 files changed, 59 insertions, 62 deletions
diff --git a/sbuild/sbuild-custom-error.h b/sbuild/sbuild-custom-error.h index 0a562b20..76ad3714 100644 --- a/sbuild/sbuild-custom-error.h +++ b/sbuild/sbuild-custom-error.h @@ -39,12 +39,32 @@ namespace sbuild typedef std::map<error_type,const char *> map_type; /** + * Null class to represent an absence of context or detail in an + * error. + */ + class null + { + /** + * null output to an ostream. + * @todo Output placeholder text. + */ + template <class charT, class traits> + friend + std::basic_ostream<charT,traits>& + operator << (std::basic_ostream<charT,traits>& stream, + null const& n) + { + return stream; + } + }; + + /** * The constructor. * * @param error the error code. */ custom_error (error_type error): - runtime_error(format_error(std::string(), error)) + runtime_error(format_error(null(), null(), error, null(), null())) { } @@ -56,29 +76,33 @@ namespace sbuild */ custom_error (std::string const& detail, error_type error): - runtime_error(format_error(detail, error)) + runtime_error(format_error(detail, null(), error, null(), null())) { } /** * The constructor. * - * @param detail the details of the error. + * @param error the error code. + * @param error_string the error string. */ - custom_error (std::string const& detail): - runtime_error(detail) + custom_error (error_type error, + std::string const& error_string): + runtime_error(format_error(null(), null(), error, error_string, null())) { } /** * The constructor. * + * @param detail the details of the error. * @param error the error code. * @param error_string the error string. */ - custom_error (error_type error, + custom_error (std::string const& detail, + error_type error, std::string const& error_string): - runtime_error(format_error(std::string(), error, error_string)) + runtime_error(format_error(detail, null(), error, error_string, null())) { } @@ -87,12 +111,9 @@ namespace sbuild * * @param detail the details of the error. * @param error the error code. - * @param error_string the error string. */ - custom_error (std::string const& detail, - error_type error, - std::string const& error_string): - runtime_error(format_error(detail, error, error_string)) + custom_error (std::runtime_error const& error): + runtime_error(format_error(null(), null(), error, null(), null())) { } @@ -100,11 +121,11 @@ namespace sbuild * The constructor. * * @param detail the details of the error. - * @param error_string the error string. + * @param error the error code. */ - custom_error (std::string const& detail, - std::string const& error_string): - runtime_error(format_error(detail, error_string)) + custom_error (std::string const& detail, + std::runtime_error const& error): + runtime_error(format_error(detail, null(), error, null(), null())) { } @@ -128,64 +149,40 @@ namespace sbuild /** * Format an error message. * + * @param context1 context of the error. + * @param context2 additional context of the error. * @param error the error code. - * @param detail the details of the error. - * @returns a translated error message. - */ - static std::string - format_error (std::string const& detail, - error_type error); - - /** - * Format an error message. - * - * @param detail the details of the error. - * @param error the error code. - * @param error_number the error number. - * @returns a translated error message. - */ - static std::string - format_error (std::string const& detail, - error_type error, - int error_number); - - /** - * Format an error message. - * - * @param detail the details of the error. - * @param error_number the error number. + * @param detail1 details of the error. + * @param detail2 additional details of the error. * @returns a translated error message. */ - static std::string - format_error (std::string const& detail, - int error_number); + template <typename A, typename B, typename C, typename D> + std::string + format_error (A const& context1, + B const& context2, + error_type error, + C const& detail1, + D const& detail2); /** * Format an error message. * - * @param detail the details of the error. + * @param context1 context of the error. + * @param context2 additional context of the error. * @param error the error code. - * @param error_string the error string. - * @returns a translated error message. - */ - static std::string - format_error (std::string const& detail, - error_type error, - std::string const& error_string); - - /** - * Format an error message. - * - * @param detail the details of the error. - * @param error_string the error string. + * @param detail1 details of the error. + * @param detail2 additional details of the error. * @returns a translated error message. */ - static std::string - format_error (std::string const& detail, - std::string const& error_string); + template <typename A, typename B, typename C, typename D> + std::string + format_error (A const& context1, + B const& context2, + std::runtime_error const& error, + C const& detail1, + D const& detail2); }; - } #include "sbuild-custom-error.tcc" |