DEV Community

Discussion on: Error handling - Returning Results

Collapse
 
michael_altmann profile image
Michael Altmann

I don't say that it is completely forbidden to use exceptions. Using exceptions is a great way to handle errors we don't know how to deal with. If its really an exceptional situation it should be logged somehow, for example in a error reporting software. In this case exceptions are great.

But for errors we know how to deal with it was for us a great benefit to use exceptions. For example we implemented a CSV Upload in C# and the CSV have to be valid, so the file have to pass many validation rules successfully. First we implemented it with exceptions => bad idea. One problem was that we want to display all broken validation rules and not only the first one.
Then we implemented a very basic Result object and tried it. We were satisfied with the code and so we also used this Result object in other components in our software. Until now we are very satisfied with it.