TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

What do you do when you've caught an exception?

9 点作者 paul_houle大约 16 年前

3 条评论

damienkatz大约 16 年前
Set it free. If it crashes the program, it was yours all along.
评论 #500274 未加载
russell大约 16 年前
Paul makes some very good points. He advocates exception handling at the level of the unit of work. The problem is what is the unit of work? As an example, I was setting up a new Jboss installation and deployment of an application that I am only getting familiar with. Catalina threw an exception about something in the configuration, but didn't log anything. Finally, JBoss caught the exception and just logged that the deployment had failed. The piece of code that found the problem could have told me what was wrong.<p>Paul says that checked exception are a horrible mistake, because they cause premature catching of exceptions, because ignoring the exception means that the programmer has to change the signature of his method. I find swallowed exceptions all over the place in reading code. And methods in the Sun libraries exacerbate the problem by throwing multiple checked exceptions that have to be swallowed. So to keep method signatures at a reasonable length, more swallowed exceptions. Generic exceptions with error codes, like SQLException, would make more sense.<p>Given the reality of Java Exception handling, I favor catching the exception at the point where a reasonable error message can be composed and logged., Then throwing an unchecked exception to be caught at the level of the unit of work.<p>Finally, Paul says always use finally to clean up your mess.
lbolognini大约 16 年前
Is it any good fried?