Lazy try{}?
843810Jan 29 2007 — edited Jan 29 2007Hi everyone, I'm new to this forums (as a writer... I've used it lots of times to solve obscure problems).
I'm using a workaround for thread exception handling, the typical Exception field to store possible errors that can be later retrieved and processed (by the main thread), in this case in another class called ExceptionArea.
The code is as follows:
public abstract class Task extends Thread {
private ExceptionArea ea;
public Task(ExceptionArea ea) {
this.ea = ea;
}
public void run() {
try {
exceptionRun();
}
catch (Exception e) {
try {
ea.setException(e);
}
catch (Exception e1) {
}
}
}
public abstract void exceptionRun() throws Exception;
}
Were "ea" is a class to store the exception, and "exceptionRun" is the abtract method wich do the concrete work.
So I create a subclass, implement "exceptionRun", and when an exception rises from subclasses, instead of stopping in the try{} block, the hole program crashes on "exceptionRun(ea)", as you can see in the:
jxl.read.biff.PasswordException: The workbook is password protected
at jxl.read.biff.WorkbookParser.parse(WorkbookParser.java:580)
at jxl.Workbook.getWorkbook(Workbook.java:237)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at org.coac.plaquessolars.io.in.JXL.<init>(JXL.java:18)
at org.coac.plaquessolars.habitatge.DadesHabitatge.<init>(DadesHabitatge.java:26)
at org.coac.plaquessolars.habitatge.Habitatge.carrega(Habitatge.java:45)
at org.coac.plaquessolars.habitatge.CarregadorHabitatge.exceptionRun(CarregadorHabitatge.java:15)
at org.coac.plaquessolars.util.Task.run(Task.java:14)
PasswordException is a subclass of java.lang.Exception (actually, a sub-sub-subclass). I've tried to specifycally catch "PasswordException", but it neither results.
I'm thinking about 2 causes for this problem, but none satifies me:
- there is a way to make an exception "uncaughtable".
- you cannot catch an exception inside the "run" method of a thread.
If you need more info or code, feel free to ask. I hope the answer was a silly thing...
Thanks, and sorry for the looong post.
Oriol