I have a user control that contains several methods, and each of these methods has a try-catch block. I catch only one type of exception, for example ArgumentException. Update. I do not see an exception, except for a few exceptions that I defined.
Each of these methods handles an ArgumentException in the same way, so I have redundant code.
Can I catch an ArgumentException in one place to use all methods in a user element?
Update1: The application is used in production, and it is used by many people who are not very familiar with computers. Simplified - they have to insert a lot of numbers into the database (using a hand-held optical scanner), and, of course, they make mistakes. There are at least 8 common exceptions (wrong size, wrong type, ...), and in my business logic I catch all these exceptions and throw them into the GUI. Since the environment in which the application is installed is very disgusting, I play a loud error sound and display an error message.
Because of the business logic, they have several options for inserting these numbers, so the same error detection logic is found in several methods throughout the user control.
Update2: in fact, I will not catch an ArgumentException, but my own exceptions like CodeFormatException, CodeDoesntExistException, CodeNotInTheSelectedRollException etc.
source
share