try catch in presentation layer - best practice

250 views Asked by At

I have a layered architecture application. All the error handling is done at business layer and data layer throws the error to business layer. Presentation layer shows this custom error to user. Along with that I have a common error page where the HTTP related errors are going. I don’t have any try catch block in presentation layer.

But I need to know the best practice to handle the presentation layer error. Assume like the user expect to enter some decimal numbers, but some characters appended along with that. So how can I handle such kind of error? Should I write code to handle that without writing try catch or should have try catch in my presentation layer code?

Another scenario is I am reading one file from a location, but if the file is not present there, then I should catch this in try catch block or presentation or I should write code for all possible errors?

Thanks

1

There are 1 answers

0
Olivier Meurice On

For the presentation layer you should validate user entries. Add validations on the screens. User entries must be validated before being sent to the server. And also validate your model server-side. For instance if user is requested to enter a decimal value, check that it is actually a decimal value on the client side and server side next to the form submission. On the page you may mark the fields that are in error with a red box or a red mark on its right side and display the error message just below the field for instance. That is usually how errors are reported to the user. You may also choose to display the error message as a tooltip but in any case the field in error must be marked as such. You can check some demo here: http://scotch.io/demos/angular-validation