I know this is an Anti-Pattern, but in my RESTful application I want to log and throw.
I have this Code
log.warn("Cannot determine provider from name: " + name);
throw X.bad("Cannot determine provider from name: " + name);
This is a situation that shouldn't happen - it is just the last else in a series of if/else if. However in case it does happen it might indicate a front-end bug/error.
- My restful stack can deal with exceptions and map them to HTTP responses.
- I also want a log entry with a good stacktrace.
- I would like the log entry to pertain to the place it was thrown from (I.e. logger category (class name) and stacktrace.
I did think of putting a log.warn(...) inside X.bad() but then the logging class is X and the stacktrace is bigger than it was when the exception was needed to be thrown.
Does anyone have a more integrated solution?
(I think to stop the repetition of the text component more then anything)
Thanks
Rob