What is "exception"
This is one of the most poorly understood mechanisms by programmers so it needs a lot of study. Not everyone agrees on the right way to use it. Some languages have more culture of their use and each with a slightly different way.
We have questions here that we can consider as canonical and reading them will learn a lot of what you need to solve your problem:
- Why should we avoid returning error codes?
- There is some drawback in always catching Exception and not something more specific?
- Exceptions consume a lot of processing. Truth or legend?
- Best way to deal with Exceptions
- Exceptions should be used for flow control?
- How to best treat exceptions in Java?
See also: throw.