如何避免用户在服务器抛出异常时获得500错误 [英] How to avoid users getting 500 Errors when server throw exception

查看:1300
本文介绍了如何避免用户在服务器抛出异常时获得500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 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.有关更多详细信息,请参阅位于D:/ Lotus / Domino /数据/多米诺骨牌/工作空间/日志



用户只能在webbrowser(源)中看到这个。

 < html> 
< head>
< title>错误< / title>< / head>
< body text =#000000>
< h1>错误500< / h1> HTTP Web服务器:命令未处理异常< / body>
< / html>

所以我可以告诉服务器日志在服务器上抛出一个安全异常,可能是因为我的java.policy文件中的设置错误。但我的问题不是导致错误的原因,而是如何避免用户获得这些丑陋的500错误。



我想要在



可能?

解决方案

div>

你的代码中的try / catch块越多越好(在理由当然):

 尝试{
//可能抛出错误的代码
} catch(e){
//检查错误以查看是否有解决方法
//如果没有,则记录它通知用户
} finally {
//任何需要运行的代码是否有错误
}

这样一来,如果某些事情失败,它就会失效。只需确保向用户明确出现某些问题(并且最好提供他们实际可以跟进的指示)...如果出现问题,用户认为这个错误页面比一个丑陋的错误页面更糟糕一切都很好。



PS正如Stephan所说,有一些错误根本无法被抓住。如果XPage没有由有权访问运行XPage的人签名,例如,它甚至没有到达尝试运行代码的地步...页面本身是无效的,所以在运行时没有什么可以做的。始终确保您的XPage在部署过程中签名。


I get the following errors in my server log.

  • 2012-03-06 09:20:43 HTTP JVM: CLFAD0211E: Exception thrown. For more detailed information, please consult error-log-0.xml located in D:/Lotus/Domino/data/domino/workspace/logs
  • 2012-03-06 09:20:43 HTTP JVM: CLFAD0229E: Security exception occurred servicing request for: /demo.nsf/home.xsp - HTTP Code: 500. For more detailed information, please consult error-log-0.xml located in D:/Lotus/Domino/data/domino/workspace/logs

The user only sees this in the webbrowser (source)

<html>
<head>
<title>Error</title></head>
<body text="#000000">
<h1>Error 500</h1>HTTP Web Server: Command Not Handled Exception</body>
</html>

So I can tell by the server log that there is a security exception thrown at the server, probably because I have wrong settings in my java.policy file. but my issue is not what is causing the error, but rather how can I avoid users getting these ugly 500 errors.

I would like the error page I have set in the application to be presented to the user just like any other exception.

possible?

解决方案

The more try/catch blocks you have in your code, the better (within reason, of course):

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
}

This way if something fails, it fails gracefully. Just be sure to make it obvious to the user that something went wrong (and, preferably, provide them instructions they can actually follow up on)... failing silently is even worse than an ugly error page if something went wrong and the user thinks everything was fine.

P.S. As Stephan indicates, there are some errors that simply can't be caught. If the XPage wasn't signed by someone with access to run XPages, for instance, it never even gets to the point of trying to run your code... the page itself is invalid, so there's nothing you can do at runtime. Always make sure that your XPages are signed during deployment.

这篇关于如何避免用户在服务器抛出异常时获得500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆