我的服务器日志中出现以下错误。
- 2012-03-06 09:20:43 HTTP JVM:CLFAD0211E:引发异常。有关更详细的信息,请查阅位于 D:/Lotus/Domino/data/domino/workspace/logs 的 error-log-0.xml
- 2012-03-06 09:20:43 HTTP JVM:CLFAD0229E:服务请求发生安全异常:/demo.nsf/home.xsp - HTTP 代码:500。有关更多详细信息,请查阅 error-log-0.xml位于 D:/Lotus/Domino/data/domino/workspace/logs
用户仅在网络浏览器中看到此内容(来源)
<html>
<head>
<title>Error</title></head>
<body text="#000000">
<h1>Error 500</h1>HTTP Web Server: Command Not Handled Exception</body>
</html>
所以我可以通过服务器日志判断服务器抛出了安全异常,可能是因为我的 java.policy 文件中的设置错误。但我的问题不是导致错误的原因,而是如何避免用户收到这些丑陋的 500 错误。
我希望将我在应用程序中设置的错误页面呈现给用户,就像任何其他异常一样。
可能的?
代码中的 try/catch 块越多越好(当然,在合理范围内):
try {
// code that might throw an error
} catch (e) {
// examine the error to see if there's a workaround
// if not, log it and inform the user
} finally {
// any code that needs to run whether or not there was an error
}
这样,如果某件事失败了,它就会优雅地失败。只要确保让用户清楚地知道出了问题(并且最好向他们提供他们可以实际跟进的说明)...如果出现问题并且用户认为出现问题,那么默默地失败甚至比丑陋的错误页面更糟糕一切都很好。
附:正如 Stephan 所指出的,有些错误根本无法被发现。例如,如果 XPage 没有由有权运行 XPage 的人签名,那么它甚至永远不会尝试运行您的代码...页面本身无效,因此您在运行时无能为力。始终确保您的 XPage 在部署期间经过签名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)