From b5ac92491c1b40bb40f71c6ca629b2347fbdd9ef Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Sat, 3 Aug 2013 17:23:06 -0700 Subject: [PATCH] Throw std::exception subclasses instead of std::strings Now everything we throw or catch ourselves is a subclass of std::exception. --- src/frontend/mosh-client.cc | 4 ++-- src/terminal/terminaldisplayinit.cc | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 9f48dfc..75894e2 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -181,8 +181,8 @@ int main( int argc, char *argv[] ) } catch ( const Crypto::CryptoException &e ) { fprintf( stderr, "Crypto exception: %s\r\n", e.what() ); - } catch ( const std::string &s ) { - fprintf( stderr, "Error: %s\r\n", s.c_str() ); + } catch ( const std::exception &e ) { + fprintf( stderr, "Error: %s\r\n", e.what() ); } printf( "\n[mosh is exiting.]\n" ); diff --git a/src/terminal/terminaldisplayinit.cc b/src/terminal/terminaldisplayinit.cc index 80ba467..6a0886e 100644 --- a/src/terminal/terminaldisplayinit.cc +++ b/src/terminal/terminaldisplayinit.cc @@ -37,6 +37,7 @@ #include "terminaldisplay.h" #include +#include #if defined HAVE_NCURSESW_CURSES_H # include @@ -65,7 +66,7 @@ bool Display::ti_flag( const char *capname ) const { int val = tigetflag( const_cast( capname ) ); if ( val == -1 ) { - throw std::string( "Invalid terminfo boolean capability " ) + capname; + throw std::invalid_argument( std::string( "Invalid terminfo boolean capability " ) + capname ); } return val; } @@ -74,7 +75,7 @@ int Display::ti_num( const char *capname ) const { int val = tigetnum( const_cast( capname ) ); if ( val == -2 ) { - throw std::string( "Invalid terminfo numeric capability " ) + capname; + throw std::invalid_argument( std::string( "Invalid terminfo numeric capability " ) + capname ); } return val; } @@ -83,7 +84,7 @@ const char *Display::ti_str( const char *capname ) const { const char *val = tigetstr( const_cast( capname ) ); if ( val == (const char *)-1 ) { - throw std::string( "Invalid terminfo string capability " ) + capname; + throw std::invalid_argument( std::string( "Invalid terminfo string capability " ) + capname ); } return val; } @@ -98,16 +99,16 @@ Display::Display( bool use_environment ) if ( ret != OK ) { switch ( errret ) { case 1: - throw std::string( "Terminal is hardcopy and cannot be used by curses applications." ); + throw std::runtime_error( "Terminal is hardcopy and cannot be used by curses applications." ); break; case 0: - throw std::string( "Unknown terminal type." ); + throw std::runtime_error( "Unknown terminal type." ); break; case -1: - throw std::string( "Terminfo database could not be found." ); + throw std::runtime_error( "Terminfo database could not be found." ); break; default: - throw std::string( "Unknown terminfo error." ); + throw std::runtime_error( "Unknown terminfo error." ); break; } }