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
@@ -34,7 +34,6 @@
|
||||
#include "version.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "stmclient.h"
|
||||
@@ -177,11 +176,11 @@ int main( int argc, char *argv[] )
|
||||
|
||||
client.shutdown();
|
||||
} catch ( const Network::NetworkException& e ) {
|
||||
fprintf( stderr, "Network exception: %s: %s\r\n",
|
||||
e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "Network exception: %s\r\n",
|
||||
e.what() );
|
||||
} catch ( const Crypto::CryptoException& e ) {
|
||||
fprintf( stderr, "Crypto exception: %s\r\n",
|
||||
e.text.c_str() );
|
||||
e.what() );
|
||||
} catch ( const std::string& s ) {
|
||||
fprintf( stderr, "Error: %s\r\n", s.c_str() );
|
||||
}
|
||||
|
||||
@@ -311,12 +311,12 @@ int main( int argc, char *argv[] )
|
||||
try {
|
||||
return run_server( desired_ip, desired_port, command_path, command_argv, colors, verbose, with_motd );
|
||||
} catch ( const Network::NetworkException& e ) {
|
||||
fprintf( stderr, "Network exception: %s: %s\n",
|
||||
e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "Network exception: %s\n",
|
||||
e.what() );
|
||||
return 1;
|
||||
} catch ( const Crypto::CryptoException& e ) {
|
||||
fprintf( stderr, "Crypto exception: %s\n",
|
||||
e.text.c_str() );
|
||||
e.what() );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -491,11 +491,11 @@ int run_server( const char *desired_ip, const char *desired_port,
|
||||
try {
|
||||
serve( master, terminal, *network );
|
||||
} catch ( const Network::NetworkException& e ) {
|
||||
fprintf( stderr, "Network exception: %s: %s\n",
|
||||
e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "Network exception: %s\n",
|
||||
e.what() );
|
||||
} catch ( const Crypto::CryptoException& e ) {
|
||||
fprintf( stderr, "Crypto exception: %s\n",
|
||||
e.text.c_str() );
|
||||
e.what() );
|
||||
}
|
||||
|
||||
#ifdef HAVE_UTEMPTER
|
||||
@@ -727,13 +727,13 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
||||
|
||||
network.tick();
|
||||
} catch ( const Network::NetworkException& e ) {
|
||||
fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "%s\n", e.what() );
|
||||
spin();
|
||||
} catch ( const Crypto::CryptoException& e ) {
|
||||
if ( e.fatal ) {
|
||||
throw;
|
||||
} else {
|
||||
fprintf( stderr, "Crypto exception: %s\n", e.text.c_str() );
|
||||
fprintf( stderr, "Crypto exception: %s\n", e.what() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ void STMClient::main( void )
|
||||
throw;
|
||||
} else {
|
||||
wchar_t tmp[ 128 ];
|
||||
swprintf( tmp, 128, L"Crypto exception: %s", e.text.c_str() );
|
||||
swprintf( tmp, 128, L"Crypto exception: %s", e.what() );
|
||||
overlays.get_notification_engine().set_notification_string( wstring( tmp ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <limits.h>
|
||||
#include <exception>
|
||||
|
||||
namespace Overlay {
|
||||
using namespace Terminal;
|
||||
@@ -173,10 +174,10 @@ namespace Overlay {
|
||||
show_quit_keystroke = s_show_quit_keystroke;
|
||||
}
|
||||
|
||||
void set_network_exception( const NetworkException &e )
|
||||
void set_network_exception( const std::exception &e )
|
||||
{
|
||||
wchar_t tmp[ 128 ];
|
||||
swprintf( tmp, 128, L"%s: %s", e.function.c_str(), strerror( e.the_errno ) );
|
||||
swprintf( tmp, 128, L"%s", e.what() );
|
||||
|
||||
message = tmp;
|
||||
message_is_network_exception = true;
|
||||
|
||||
Reference in New Issue
Block a user