Reputation: 1271
How can I set an error in Request Context rather than throw an Exception?
Like:
void valid(Object o){
if(o == null){
//add an error to Request context
//I want to avoid the throw new ....
return;
}
}
Upvotes: 0
Views: 609
Reputation: 123
I believe exception is not a functionality to be avoided. It was created for a purpose, and should be used in this way.
The problem is when devs use them to help on the application's flow, because exception is an expensive solution for that, and there are other ways for doing so.
There is nothing wrong in throwing a BadRequestException for example when there is some user input failure. Some frameworks are already expecting specific exceptions, and most of them is already prepared for treatment for customized exceptions.
Upvotes: 1