I'm working on a traditional ASP.NET application making WCF service calls.
Should I put a try catch around the WCF call and display the error details at the top of the current page; let the error redirect the user to a custom error page; or leave it up IIS / .NET framework?
Which approach is least l开发者_运维技巧ikely to confuse future developer?
Never to the yellow screen of death. The detailed information about the error can give hints to a hacker to break your site.
If the page cannot be displayed without the service request, then redirect to a custom error page.
If only a small portion of information will be missing on a page which is not key to its function, then better display a friendly message to the user that this particular piece of information is not available at the moment.
This will depend on your application requirements. Can you continue processing if the web service call fails? If not you probably should log the exception and redirect the user to a 500 page. I would use Application_Error
method in global.asax to do this. If you can continue the processing then you should put a try/catch around your web service call and handle the appropriate FaultException. You should never let customers see the yellow screen in production.
If you expect that the WCF call can throw an exception and you know which exception types you can get, then yes, you should catch the exception and perform the appropriate action. Usually it is a good idea to tell the user just that an error made the operation to fail, and log the exception detail for further examination by you or the technical support.
精彩评论