Questions tagged [exceptionhandler]
186 questions
41
votes
4 answers
Getting Ambiguous @ExceptionHandler method mapped for MethodArgumentNotValidException while startup of spring boot application
I have written custom exception handler class for one of my spring controllers to validate if email attribute from request param is in the proper format. So created a new class which extends ResponseEntityExceptionHandler class and wrote a method…

Shanmugam Thangavelu
- 413
- 1
- 4
- 6
25
votes
1 answer
$location from $exceptionHandler - dependency conflict
I'm trying to implement a very standard task: when an exception occurs, redirect to my /error page.
In a simplified form the code looks like this:
app.factory('$exceptionHandler', ['$location', function($location) {
return function(exception,…

vitaly-t
- 24,279
- 15
- 116
- 138
19
votes
4 answers
How could we use @ExceptionHandler with spring web flux?
In spring web we could use annotation @ExceptionHandler for handling server and client errors for controllers.
I've tried to use this annotation with web-flux controller and it still worked for me, but after some investigation I've found out…

Evgen
- 1,278
- 3
- 13
- 25
18
votes
1 answer
How does spring manage ExceptionHandler priority?
Giving this controller
@GetMapping("/test")
@ResponseBody
public String test() {
if (!false) {
throw new IllegalArgumentException();
}
return "blank";
}
@ResponseStatus(value =…

Olivier Boissé
- 15,834
- 6
- 38
- 56
15
votes
3 answers
Reading httprequest content from spring exception handler
I Am using Spring's @ExceptionHandler annotation to catch exceptions in my controllers.
Some requests hold POST data as plain XML string written to the request body, I want to read that data in order to log the exception.
The problem is that when i…

Noam Nevo
- 3,021
- 10
- 35
- 49
12
votes
1 answer
BindException thrown instead of MethodArgumentNotValidException in REST application
I have a simple Spring Rest Controller with some validation. My understanding is that validation failures would throw a MethodArgumentNotValidException. However, my code throws a BindException instead. In debug messages, I also see the app returning…

Jigish
- 1,764
- 1
- 15
- 20
11
votes
2 answers
Throwing an exception from @ExceptionHandler to get caught by another handler
I have a @ControllerAdvice class to handle exceptions from my SpringMVC controllers. I would like to catch an exception of a known type (RuntimeException) in an @ExceptionHandler method then throw the e.getCause() exception and have this exception…

agentgonzo
- 3,473
- 3
- 25
- 30
10
votes
5 answers
spring mvc @ExceptionHandler method get same view
My problem is that I want to create an @ExceptionHandler method that will capture all un-handled exceptions. Once captured I would like to redirect to the current page instead of specifying a separate page just to display error.
Basically how do I…

vincent
- 243
- 1
- 7
- 17
9
votes
5 answers
@ControllerAdvice and @ExceptionHandler not getting triggered for my RestController
In order to have unified exception handling throughout the application I am using Error Handling for REST with Spring solution#3 which uses @ControllerAdvice along with @ExceptionHandler.
Spring version: 4.3.22.RELEASE
Spring Boot version:…

Learner
- 1,503
- 6
- 23
- 44
6
votes
3 answers
Return HTTP status code dynamically as per the request using @ExceptionHandler
I want to return HTTPStatus code dynamically like 400, 400, 404 etc as per the response object error.
I was referred to this question - Programmatically change http response status using spring 3 restful but it did not help.
I have this Controller…

user2340345
- 793
- 4
- 16
- 38
6
votes
2 answers
Web API global error handling add custom header in response
I was wondering if it was possible to set some custom header values whenever an internal server error has occurred? I am currently doing:
public class FooExceptionHandler : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext…

Dr Schizo
- 4,045
- 7
- 38
- 77
6
votes
1 answer
Why FullAjaxExceptionHandler does not simply perform an ExternalContext#redirect()?
In OmniFaces, the FullAjaxExceptionHandler, after having found the right error page to use, calls the JSF runtime to build the view and render it instead of the page that includes the AJAX call.
Why this? IMHO it would be simpler to just perform a…

titou10
- 2,814
- 1
- 19
- 42
5
votes
2 answers
Spring-boot HttpMediaTypeNotAcceptableException is not getting caught by @ExceptionHandler in same controller
In my spring boot application, I have a controller for post request which produces and consumes JSON request and I have defined @ExceptionHandler for this controller with HttpMediaTypeNotAcceptableException for catching…

Mayank Goyal
- 87
- 1
- 11
5
votes
1 answer
"View Details " missing form Exception handler VS 2017
This could easily be the same as:
'View Details' missing from exception assistant
But I am seeing it in VS 2017. Flipping "Use Managed Compatibility Mode" doesn't seem to make a difference.
This is what the window looks like:
With "View Details"…

chrispepper1989
- 2,100
- 2
- 23
- 48
5
votes
0 answers
Spring @ControllerAdvice ExceptionHandler based on content type
We have a need to support both html and json responses in all our end points.
The html will be used by our own front-end application and json will be used by third-party API integrations.
We have used ContentNegotiatingViewResolver to use JstlView…

Anupama
- 167
- 1
- 9