Permalink
Browse files

refactored exception handling

  • Loading branch information...
1 parent 39b2b4f commit d4a7fae2735037e8acee9b779db6b5d2cacae963 @nestal nestal committed Apr 28, 2013
View
@@ -6,7 +6,6 @@ set( GRIVE_VERSION "0.3.0-pre" )
# common compile options
add_definitions( -DVERSION="${GRIVE_VERSION}" )
add_definitions( -D_FILE_OFFSET_BITS=64 )
-add_definitions( -DPROJ_NS=gr )
add_subdirectory( libgrive )
add_subdirectory( grive )
View
@@ -54,7 +54,7 @@ namespace po = boost::program_options;
void InitGCrypt()
{
if ( !gcry_check_version(GCRYPT_VERSION) )
- throw Exception() << expt::ErrMsg( "libgcrypt version mismatch" ) ;
+ throw std::runtime_error( "libgcrypt version mismatch" ) ;
// disable secure memory
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
@@ -150,7 +150,7 @@ long CurlAgent::ExecCurl(
dest->Clear() ;
CURLcode curl_code = ::curl_easy_perform(curl);
- // get the HTTTP response code
+ // get the HTTP response code
long http_code = 0;
::curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
Trace( "HTTP response %1%", http_code ) ;
@@ -165,7 +165,7 @@ long CurlAgent::ExecCurl(
Error()
<< CurlCode( curl_code )
<< Url( url )
- << expt::ErrMsg( error )
+ << CurlErrMsg( error )
<< HttpHeader( hdr )
) ;
}
@@ -27,13 +27,16 @@ namespace gr { namespace http {
struct Error : virtual Exception {} ;
// CURL error code
-typedef boost::error_info<struct CurlCodeTag, int> CurlCode ;
+typedef boost::error_info<struct CurlCodeTag, int> CurlCode ;
+
+// CURL error message
+typedef boost::error_info<struct CurlErrMsgTag, std::string> CurlErrMsg ;
// URL
typedef boost::error_info<struct UrlTag, std::string> Url ;
// HTTP headers
-typedef boost::error_info<struct HeaderTag, Header> HttpHeader ;
+typedef boost::error_info<struct HeaderTag, Header> HttpHeader ;
// HTTP response code
typedef boost::error_info<struct HttpResponseTag, int> HttpResponse ;
@@ -515,7 +515,7 @@ Json Json::Parse( DataStream *in )
BOOST_THROW_EXCEPTION(
Error()
<< JsonCApi_( "json_tokener_parse" )
- << expt::ErrMsg( ::json_tokener_error_desc(err) )
+ << ErrMsg_( ::json_tokener_error_desc(err) )
) ;
}
@@ -48,6 +48,7 @@ public :
typedef boost::error_info<struct KeyNotFound, std::string> KeyNotFound_ ;
typedef boost::error_info<struct JsonCApi, std::string> JsonCApi_ ;
typedef boost::error_info<struct Value, std::string> Value_ ;
+ typedef boost::error_info<struct ErrMsg, std::string> ErrMsg_ ;
template <typename T>
struct Val_
@@ -28,7 +28,7 @@
namespace po = boost::program_options;
-namespace PROJ_NS {
+namespace gr {
const std::string default_filename = ".grive";
const char *env_name = "GR_CONFIG";
@@ -31,7 +31,7 @@ namespace boost
}
}
-namespace PROJ_NS {
+namespace gr {
class Config
{
@@ -45,7 +45,10 @@ MD5::MD5() : m_impl( new Impl )
::gcry_error_t err = ::gcry_md_open( &m_impl->hd, GCRY_MD_MD5, 0 ) ;
if ( err != GPG_ERR_NO_ERROR )
{
- BOOST_THROW_EXCEPTION( Exception() << expt::ErrMsg( ::gcry_strerror(err) ) ) ;
+ BOOST_THROW_EXCEPTION( Exception()
+ << GCryptErr_( ::gcry_strerror(err) )
+ << GCryptApi_( "gcry_md_open" )
+ ) ;
}
}
@@ -19,6 +19,8 @@
#pragma once
+#include "util/Exception.hh"
+
#include <string>
#include <memory>
@@ -33,6 +35,10 @@ namespace crypt {
class MD5
{
public :
+ typedef boost::error_info<struct GCryptErr, std::string> GCryptErr_ ;
+ typedef boost::error_info<struct GCryptApi, std::string> GCryptApi_ ;
+
+public :
MD5() ;
~MD5() ;
@@ -28,7 +28,7 @@
#include <iterator>
#include <sstream>
-namespace PROJ_NS {
+namespace gr {
class Backtrace ;
@@ -25,7 +25,7 @@
#include <exception>
#include <string>
-namespace PROJ_NS {
+namespace gr {
class Backtrace ;
@@ -51,9 +51,6 @@ namespace expt
{
// back-trace information. should be present for all exceptions
typedef boost::error_info<struct BacktraceTag, Backtrace> Backtrace_ ;
-
- /// generic error message
- typedef boost::error_info<struct MsgTag, std::string> ErrMsg ;
}
} // end of namespace
@@ -78,7 +78,7 @@ struct stat FStat( int fd )
} // end of local functions
-namespace PROJ_NS {
+namespace gr {
File::File( ) : m_fd( -1 )
{
View
@@ -92,7 +92,7 @@ public :
// cannot allow duplicate attribute nodes
if ( child->m_type == attr && p.first != p.second )
- BOOST_THROW_EXCEPTION( Error() << expt::ErrMsg( "duplicate attribute " + child->m_name ) ) ;
+ BOOST_THROW_EXCEPTION( Error() << DupAttr_( child->m_name ) ) ;
vec.insert( p.second, child ) ;
}
View
@@ -19,6 +19,8 @@
#pragma once
+#include "util/Exception.hh"
+
#include <boost/iterator_adaptors.hpp>
#include <iosfwd>
@@ -39,6 +41,8 @@ private :
public :
class iterator ;
+ typedef boost::error_info<struct DupAttr, std::string> DupAttr_ ;
+
public :
Node() ;
Node( const Node& node ) ;
@@ -124,7 +124,7 @@ NodeSet NodeSet::operator[]( const std::string& name ) const
Node NodeSet::front() const
{
if ( empty() )
- throw Error() << expt::ErrMsg( "empty node set" ) ;
+ BOOST_THROW_EXCEPTION( Error() << EmptyNodeSet_(0) ) ;
return *m_first ;
}
@@ -19,6 +19,8 @@
#pragma once
+#include "util/Exception.hh"
+
#include "Node.hh"
#include <cstddef>
@@ -32,6 +34,8 @@ class NodeSet
public :
typedef Node::iterator iterator ;
+ typedef boost::error_info<struct EmptyNodeSet, int> EmptyNodeSet_ ;
+
public :
NodeSet() ;
NodeSet( const NodeSet& n ) ;
@@ -69,7 +69,7 @@ Node TreeBuilder::ParseFile( const std::string& file )
void TreeBuilder::ParseData( const char *data, std::size_t count, bool last )
{
if ( ::XML_Parse( m_impl->psr, data, count, last ) == 0 )
- throw Error() << expt::ErrMsg( "XML parse error" ) ;
+ BOOST_THROW_EXCEPTION( Error() << ExpatApiError("XML_Parse") );
}
Node TreeBuilder::Parse( const std::string& xml )
@@ -85,7 +85,7 @@ Node TreeBuilder::Result() const
assert( m_impl->stack.size() == 1 ) ;
if ( m_impl->stack.front().size() != 1 )
- throw Error() << expt::ErrMsg( "invalid node" ) ;
+ BOOST_THROW_EXCEPTION( Error() << LogicError(0) ) ;
return *m_impl->stack.front().begin() ;
}
@@ -19,6 +19,8 @@
#pragma once
+#include "util/Exception.hh"
+
#include <memory>
#include <string>
@@ -29,6 +31,10 @@ class Node ;
class TreeBuilder
{
public :
+ typedef boost::error_info<struct ExpatApiError_, std::string> ExpatApiError ;
+ typedef boost::error_info<struct LogicError_, int> LogicError ;
+
+public :
TreeBuilder() ;
~TreeBuilder() ;

0 comments on commit d4a7fae

Please sign in to comment.