Throwing Exceptions
Is this a totally valid / proper way of handling exceptions? For whatever reason I feel like this is improper
2 Replies
Not fully, no. You're missing a catch block. Exceptions should be handled within the code or the application will fail. This is achieved with a try-catch block (in Javascript, C# and others). Some programming languages can handle thrown exception, but it is not good practice.
When you throw an exception, it is caught by the next catch block. If there's no catch block to catch the illegal argument - and the exception is terminating, -the program will terminate unexpectedly.
Look at heading #5 in this blog. There may be multiple exceptions need caught:
https://dzone.com/articles/9-best-practices-to-handle-exceptions-in-java
ty!!