Net: unwrap the exception if it came from the user code

This commit is contained in:
Jakub Valtar
2018-01-22 13:44:43 +01:00
parent 0d12c46825
commit 2b1cd66f83
2 changed files with 18 additions and 3 deletions

View File

@@ -155,7 +155,12 @@ public class Client implements Runnable {
try {
disconnectEventMethod.invoke(parent, this);
} catch (Exception e) {
e.printStackTrace();
Throwable cause = e;
// unwrap the exception if it came from the user code
if (e instanceof InvocationTargetException && e.getCause() != null) {
cause = e.getCause();
}
cause.printStackTrace();
disconnectEventMethod = null;
}
}
@@ -266,7 +271,12 @@ public class Client implements Runnable {
clientEventMethod.invoke(parent, this);
} catch (Exception e) {
System.err.println("error, disabling clientEvent() for " + host);
e.printStackTrace();
Throwable cause = e;
// unwrap the exception if it came from the user code
if (e instanceof InvocationTargetException && e.getCause() != null) {
cause = e.getCause();
}
cause.printStackTrace();
clientEventMethod = null;
}
}

View File

@@ -308,7 +308,12 @@ public class Server implements Runnable {
serverEventMethod.invoke(parent, this, client);
} catch (Exception e) {
System.err.println("Disabling serverEvent() for port " + port);
e.printStackTrace();
Throwable cause = e;
// unwrap the exception if it came from the user code
if (e instanceof InvocationTargetException && e.getCause() != null) {
cause = e.getCause();
}
cause.printStackTrace();
serverEventMethod = null;
}
}