Dlaczego po owinięciu SwingWorker wokół tego kodu nie jest już zgłaszany wyjątek zgłaszany?Dlaczego mój wyjątek Java nie drukuje śledzenia stosu, gdy jest wyrzucany w SwingWorker?
import java.security.InvalidParameterException;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
public class Test {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
IntegerString s = new IntegerString("EIGHT");
return null;
}
}.execute();
}
});
}
}
class IntegerString {
public IntegerString(String s) {
if (!isInteger(s)) {
System.out.println("...throwing exception.");
throw new InvalidParameterException("Thrown.");
}
// ...
}
static boolean isInteger(String str) {
if (str == null) {
return false;
}
int length = str.length();
if (length == 0) {
return false;
}
int i = 0;
if (str.charAt(0) == '-') {
if (length == 1) {
return false;
}
i = 1;
}
for (; i < length; i++) {
char c = str.charAt(i);
if (c <= '/' || c >= ':') {
return false;
}
}
return true;
}
}
Czy nie jest rzucany lub nie jest zgłaszany zgodnie z oczekiwaniami? –
To nie jest zgłaszane. Zakładam, że jest wyrzucany, ale stacktrace nie drukuje. – sdasdadas
Domyślam się, że wyjątek jest nadal zgłaszany, ale wewnętrzne wywołanie funkcji 'doInBackground()' jest zapakowane w instrukcję try-catch mającą na celu ignorowanie wyjątków. – Vulcan