简体   繁体   中英

How do I extract a stacktrace from threads in Eclipse?

I'm very confused with handling errors on runnables passed to a threadpool.

I am doing everything by the book (literally, I'm adhering to Goetz' "Concurrency in Practice") and I'm not capturing any errors that Eclipse is showing me, and I'm getting weird NoClassDefFoundErrors even though my buildpath looks fine.

奇怪的NoClassDefFoundError即使我的构建路径很好

I tried killing my local repo and recloning it to get a fresh project build, but still getting the error. And none of my try-catches or System.out.println's are working either. Is there any way Eclipse can give me a better view of the error? Or a way to actually get the error handler's to work?

//ThreadPool and runnable that is failing, even with error captures
MyPriorityThreadPool.execute(new RunWithPriority(priority) {
                        Throwable thrown = null;
                        @Override
                        public void run() { 
                                try {
                                    batch.buildData();
                                } catch (Exception e) {
                                    thrown = e;
                                }
                                finally {
                                    if (thrown != null) { 
                                        thrown.printStackTrace();
                                    }
                                }
                        }
                    });
                }

I'm not quite sure what you're trying to accomplish, but the reason you're not catching the NoClassDefFoundError in your code is that you're catching Exception instead of Throwable or Error . Exception is more specific than Error and not what NoClassDefFoundError inherits from, so NoClassDefFoundError isn't caught by your catch expression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM