Make all exception classes inherit from std::exception
This refactors out a very common pattern of formatting "%s: %s" with e.function.c_str() and strerror( e.the_errno ) into just the what() method of NetworkException. It's also a prerequisite for making cleaner public API for any exceptions we throw, and allows us to more easily get exceptions passed back to us to handle.
This commit is contained in:
committed by
John Hood
parent
ebecb9bd3a
commit
5721b392ab
@@ -62,7 +62,7 @@ int main( int argc, char *argv[] )
|
||||
(long)message.nonce.val() );
|
||||
cout << message.text;
|
||||
} catch ( const CryptoException &e ) {
|
||||
cerr << e.text << endl;
|
||||
cerr << e.what() << endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
cout << ciphertext;
|
||||
} catch ( const CryptoException &e ) {
|
||||
cerr << e.text << endl;
|
||||
cerr << e.what() << endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ int main( int argc, char *argv[] )
|
||||
n = new Transport<UserStream, UserStream>( me, remote, NULL, NULL );
|
||||
}
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Fatal error: %s\n", e.text.c_str() );
|
||||
fprintf( stderr, "Fatal error: %s\n", e.what() );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
}
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.text.c_str() );
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.what() );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -164,10 +164,10 @@ int main( int argc, char *argv[] )
|
||||
n->recv();
|
||||
}
|
||||
} catch ( const NetworkException &e ) {
|
||||
fprintf( stderr, "%s: %s\r\n", e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "%s\n", e.what() );
|
||||
break;
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.text.c_str() );
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user