Reputation: 6036
I use a @ControllerAdvice for my REST service. However I can not get a full stacktrace and define where an exception occured.
My ControllerAdvice:
@ControllerAdvice
public class RestResponseEntityExceptionHandler
extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {Exception.class})
protected ResponseEntity<Object> handleException(
Exception ex, WebRequest request) {
String bodyOfResponse = "Internal error";
System.out.println(ex.toString());
return handleExceptionInternal(ex, bodyOfResponse,
new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
}
}
If an Exception occurs I receive only:
WARN 72490 --- [nio-5054-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [java.lang.NullPointerException]
How I can get a full stacktrace?
Upvotes: 1
Views: 1798
Reputation: 767
You can replace System.out.println(ex.toString());
with ex.printStackTrace();
to get where the exception occured and cause of it.
If you are using log, then use log.info("{}", ex)
Upvotes: 3