diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-09-05 18:12:39 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-09-05 18:12:39 +0200 |
commit | 73a0556dca6ff98da2a77a34e75c5eec5969cd87 (patch) | |
tree | 5f092a4074192f4031d33cc50bc7142ea11fc14f | |
parent | 9a717577d06f00bb8a0c7338f7b687540b5e017d (diff) | |
download | sqlitexx-73a0556dca6ff98da2a77a34e75c5eec5969cd87.tar.gz sqlitexx-73a0556dca6ff98da2a77a34e75c5eec5969cd87.tar.bz2 |
revised exception hierarchy, following more the pqxx ideas
-rw-r--r-- | include/sqlite3xx/except.hpp | 30 | ||||
-rw-r--r-- | src/except.cpp | 34 | ||||
-rw-r--r-- | tests/test2.cpp | 2 | ||||
-rw-r--r-- | tests/test3.cpp | 2 | ||||
-rw-r--r-- | tests/test4.cpp | 2 | ||||
-rw-r--r-- | tests/test5.cpp | 2 | ||||
-rw-r--r-- | tests/test6.cpp | 2 | ||||
-rw-r--r-- | tests/test7.cpp | 2 | ||||
-rw-r--r-- | tests/test8.cpp | 2 | ||||
-rw-r--r-- | tests/test9.cpp | 6 |
10 files changed, 53 insertions, 31 deletions
diff --git a/include/sqlite3xx/except.hpp b/include/sqlite3xx/except.hpp index 2577e85..6a70216 100644 --- a/include/sqlite3xx/except.hpp +++ b/include/sqlite3xx/except.hpp @@ -32,20 +32,40 @@ using namespace std; namespace sqlite3xx { -class SQLITEXX_LIBEXPORT sql_error : runtime_error { - string _m; - string _q; +class SQLITEXX_LIBEXPORT sqlitexx_exception { + public: + virtual ~sqlitexx_exception( ) throw( ) = 0; + + virtual exception &base( ) throw( ) = 0; +}; + +class SQLITEXX_LIBEXPORT failure : public sqlitexx_exception, public runtime_error +{ + virtual exception &base( ) throw( ) { return *this; } + + public: + explicit failure( const string &s ); +}; + +class SQLITEXX_LIBEXPORT sql_error : public failure { + string m_q; public: sql_error( ); - explicit sql_error( string& q ); - explicit sql_error( string& __m, string& q ); + explicit sql_error( const string& _q ); + explicit sql_error( const string& _m, const string& _q ); virtual ~sql_error( ) throw( ); const string& msg( ) const throw( ); const string& query( ) const throw( ); }; +/* +class SQLITEXX_LIBEXPORT db_locked : sql_error { + public: + explicit db_locket( string &q ); +}; +*/ } #endif /* SQLITE3XX_EXCEPT_H */ diff --git a/src/except.cpp b/src/except.cpp index cda8c7f..5ae357d 100644 --- a/src/except.cpp +++ b/src/except.cpp @@ -20,33 +20,35 @@ namespace sqlite3xx { -sql_error::sql_error( ) : - runtime_error( "failed query" ), - _m( ), - _q( ) { +sqlitexx_exception::~sqlitexx_exception( ) throw( ) +{ } -sql_error::sql_error( string& __m ) : - runtime_error( __m ), - _m( __m ), - _q( ) { +failure::failure( const string &_what ) + : sqlitexx_exception( ), runtime_error( _what ) +{ } -sql_error::sql_error( string& __m, string& q ) : - runtime_error( __m ), - _m( __m ), - _q( q ) { +sql_error::sql_error( ) + : failure( "failed query" ), m_q( ) +{ } -sql_error::~sql_error( ) throw( ){ +sql_error::sql_error( const string &_what ) + : failure( _what ), m_q( ) +{ +} + +sql_error::sql_error( const string &_what, const string &_q ) + : failure( _what ), m_q( _q ) +{ } -const string& sql_error::msg( ) const throw( ) { - return _m; +sql_error::~sql_error( ) throw( ){ } const string& sql_error::query( ) const throw( ) { - return _q; + return m_q; } } /* namespace sqlite3xx */ diff --git a/tests/test2.cpp b/tests/test2.cpp index 95b0f0a..349c159 100644 --- a/tests/test2.cpp +++ b/tests/test2.cpp @@ -67,6 +67,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test3.cpp b/tests/test3.cpp index 16ce68f..e5ac76c 100644 --- a/tests/test3.cpp +++ b/tests/test3.cpp @@ -97,6 +97,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test4.cpp b/tests/test4.cpp index b9dd69e..43ac207 100644 --- a/tests/test4.cpp +++ b/tests/test4.cpp @@ -73,6 +73,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test5.cpp b/tests/test5.cpp index e67c4ad..6f550b4 100644 --- a/tests/test5.cpp +++ b/tests/test5.cpp @@ -44,6 +44,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test6.cpp b/tests/test6.cpp index d8837f1..2dfb61c 100644 --- a/tests/test6.cpp +++ b/tests/test6.cpp @@ -63,6 +63,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test7.cpp b/tests/test7.cpp index a4ad588..65f2438 100644 --- a/tests/test7.cpp +++ b/tests/test7.cpp @@ -72,6 +72,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test8.cpp b/tests/test8.cpp index c4a5ae8..2bf59b0 100644 --- a/tests/test8.cpp +++ b/tests/test8.cpp @@ -95,6 +95,6 @@ int main( ) { cout << "end." << endl; } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } diff --git a/tests/test9.cpp b/tests/test9.cpp index bbcddb6..7c217cf 100644 --- a/tests/test9.cpp +++ b/tests/test9.cpp @@ -73,7 +73,7 @@ static THREAD_FUNC_DECL produce( void *thread_data ) } } } catch( sql_error& e ) { - cerr << "producer error, " << e.msg( ) << ": " << e.query( ) << endl; + cerr << "producer error, " << e.what( ) << ": " << e.query( ) << endl; } THREAD_FUNC_RETURN; @@ -115,7 +115,7 @@ static THREAD_FUNC_DECL consume( void *thread_data ) } } } catch( sql_error& e ) { - cerr << "consumer error, " << e.msg( ) << ": " << e.query( ) << endl; + cerr << "consumer error, " << e.what( ) << ": " << e.query( ) << endl; } THREAD_FUNC_RETURN; @@ -158,7 +158,7 @@ int main( ) { MUTEX_CLEANUP( cout_mutex ); } catch( sql_error& e ) { - cerr << e.msg( ) << ": " << e.query( ) << endl; + cerr << e.what( ) << ": " << e.query( ) << endl; } } |