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
@@ -260,9 +260,9 @@ Connection::Connection( const char *desired_ip, const char *desired_port ) /* se
|
||||
try {
|
||||
if ( try_bind( desired_ip, desired_port_low, desired_port_high ) ) { return; }
|
||||
} catch ( const NetworkException& e ) {
|
||||
fprintf( stderr, "Error binding to IP %s: %s: %s\n",
|
||||
fprintf( stderr, "Error binding to IP %s: %s\n",
|
||||
desired_ip,
|
||||
e.function.c_str(), strerror( e.the_errno ) );
|
||||
e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,8 +270,8 @@ Connection::Connection( const char *desired_ip, const char *desired_port ) /* se
|
||||
try {
|
||||
if ( try_bind( NULL, desired_port_low, desired_port_high ) ) { return; }
|
||||
} catch ( const NetworkException& e ) {
|
||||
fprintf( stderr, "Error binding to any interface: %s: %s\n",
|
||||
e.function.c_str(), strerror( e.the_errno ) );
|
||||
fprintf( stderr, "Error binding to any interface: %s\n",
|
||||
e.what() );
|
||||
throw; /* this time it's fatal */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user