I would agree with your logic in your example, however, what exception do you think you are handling in the exception handling block against your program test? I suspect your exception handling unit is really βin case something happens.β So it really comes down to an exception handling rule.
If you do not need to handle the exception, and do not handle it at a separate architectural boundary. If it is on the edge of the component border, you can wrap it by placing the original in an internal exception.
If the functionality was called from code, you would either want to check the result with some representation of the state as an answer (HRESULT is a prime example of this. 0 == SUCCESS,! = 0 == failure) or use exceptions.
Testing for software errors or component failures is where you will use exceptions, if you are checking for user input in the user interface, you can simply use logical and return status codes to report an error to the user.
Finally think about localization. If you are pulsing an error message in English through the system and presenting it to your French-speaking user, that will not be useful, and you do not want to start parsing strings in the user interface to create the French version, so exceptions are a way as long as useful The exception load has enough information to create a useful error message for the user to take corrective actions.
Use a status code, where you have a tight connection between components and the calling component, know what to do in different state states.
BTW You might want to write a stack trace, as well as just a message using ToString (), as it will give you more useful information to solve the problem.
NTN
Philip
source share