(I moved this question here, as StackExchange fits better, originally I posted it on StackOverflow.)
This is not a question about a particular piece of code, rather I ask what is the right design approach in such situations.
More on the situation:
I am developing a sort of exception handling framework for a Spring Boot REST application. Although this is a bit grandiose naming for introducing the standard Spring
@ControllerAdvice + @ExceptionHandler mechanism to the project, also a custom (parent) exception is introduced to mark the functional problems for the project.
I might be overthinking it, but is it OK to explicitly throw exceptions from the private methods of the business functional classes? Keep in mind that the business functional classes form something like an API for the Business Domain, as in DDD. This is the approach with less code, also most clear from a developer point of view, because I throw the exception exactly where the problems comes up. But if I wait (
try-catch-finally) for the problem in public method, I might gain the ability to document it with
throws declaration, also the clients of that business functionality with benefit from the increased readability.
Also, is throwing exceptions, especially, deliberately from private methods a sort of security risk? As it would expose the methods call stack in the stacktrace in the log?