sbuild-custom-error.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software; you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
00017  *
00018  *********************************************************************/
00019 
00020 #ifndef SBUILD_CUSTOM_ERROR_H
00021 #define SBUILD_CUSTOM_ERROR_H
00022 
00023 #include <sbuild/sbuild-error.h>
00024 
00025 #include <map>
00026 #include <string>
00027 
00028 namespace sbuild
00029 {
00030 
00034   template <typename T>
00035   class custom_error : public runtime_error
00036   {
00037   public:
00038     typedef T error_type;
00039     typedef std::map<error_type,const char *> map_type;
00040 
00046     custom_error (error_type error):
00047       runtime_error(format_error(std::string(), error))
00048     {
00049     }
00050 
00057     custom_error (std::string const& detail,
00058                    error_type error):
00059       runtime_error(format_error(detail, error))
00060     {
00061     }
00062 
00068     custom_error (std::string const& detail):
00069       runtime_error(detail)
00070     {
00071     }
00072 
00079     custom_error (error_type error,
00080                   int        error_number):
00081       runtime_error(format_error(std::string(), error, error_number))
00082     {
00083     }
00084 
00092     custom_error (std::string const& detail,
00093                   error_type         error,
00094                   int                error_number):
00095       runtime_error(format_error(detail, error, error_number))
00096     {
00097     }
00098 
00105     custom_error (std::string const& detail,
00106                   int                error_number):
00107       runtime_error(format_error(detail, error_number))
00108     {
00109     }
00110 
00117     custom_error (error_type         error,
00118                   std::string const& error_string):
00119       runtime_error(format_error(std::string(), error, error_string))
00120     {
00121     }
00122 
00130     custom_error (std::string const& detail,
00131                   error_type         error,
00132                   std::string const& error_string):
00133       runtime_error(format_error(detail, error, error_string))
00134     {
00135     }
00136 
00143     custom_error (std::string const& detail,
00144                   std::string const& error_string):
00145       runtime_error(format_error(detail, error_string))
00146     {
00147     }
00148 
00150     virtual ~custom_error () throw ()
00151     {}
00152 
00153   private:
00155     static map_type error_strings;
00156 
00163     static const char *
00164     get_error (error_type error);
00165 
00173     static std::string
00174     format_error (std::string const& detail,
00175                   error_type         error);
00176 
00185     static std::string
00186     format_error (std::string const& detail,
00187                   error_type         error,
00188                   int                error_number);
00189 
00197     static std::string
00198     format_error (std::string const& detail,
00199                   int                error_number);
00200 
00209     static std::string
00210     format_error (std::string const& detail,
00211                   error_type         error,
00212                   std::string const& error_string);
00213 
00221     static std::string
00222     format_error (std::string const& detail,
00223                   std::string const& error_string);
00224   };
00225 
00226 
00227 }
00228 
00229 #include "sbuild-custom-error.tcc"
00230 
00231 #endif /* SBUILD_CUSTOM_ERROR_H */
00232 
00233 /*
00234  * Local Variables:
00235  * mode:C++
00236  * End:
00237  */

Generated on Thu Jul 6 19:21:41 2006 for schroot by  doxygen 1.4.7