[JAVA] Types of exceptions in business systems
What is this?
- A summary of ideas about exceptions to business systems that use the Java language.
- A summary of the results of hearing and hearing rather than coming up from 0
- Because it is a memo, I do not write it very carefully.
Java exception
- Check exception
- Unchecked exception
It doesn't matter which one you use, but it's annoying to try-catch every exception in the business logic, so I think it's easier to do it with unchecked exceptions. (You only need to handle exceptions that reduce the amount of code and are of interest. However, if you want to specify the exception you want to handle (there is an absolute reason to force it), may it be a checked exception?)
However, there are various controversies about what to do with checked and unchecked exceptions, so I will not go into it here and be careful when designing if necessary. (Think from the perspective of the provider, the perspective of the user, the requirements of the application, etc.)
Business perspective exception
- You can continue your business (an error that allows you to do business by changing something (correcting the input value, etc.). There is a case where the user can avoid something.)
- Simple exception throw: A normal throw XxxxException-like one.
- Exceptions of the type of warning: Exceptions for cases where you want to be able to continue the business flow simply by issuing a warning such as "I haven't created XX, but can I really register?"
- Exceptions that are issued in large numbers at once: It is annoying that exceptions are issued one by one for each "input" → "confirmation" → "correction", so if you say "I want you to say everything you want to say!" .. Exceptions for these cases.
- Exceptions that business cannot be continued (Errors such as not being able to connect to the DB, not being able to connect to the other party's system, or being unable to operate the system in the first place. The case where the user can do nothing.)
Consider whether to realize these exceptions as checked exceptions or unchecked exceptions.