PDA

View Full Version : How to find the ErrorCode using SimpleMappingExceptionResolver


qualle
Dec 7th, 2007, 04:11 AM
Hallo, I'm using:

<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.Sim pleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">ID_Exception</prop>
</props>
</property>
</bean>

and

<bean id="ID_Exception" class="....MY_Exception" />
and my Controller shows as:

public class MY_Exception implements HandlerExceptionResolver{
public ModelAndView resolveException (
HttpServletRequest request,
HttpServletResponse response,
Object handler,
Exception ex )
{ ..... }
}
Is there any way to find the Error code of an Exception. For example 404, 500 etc ... I get a null when I use ex.getMessage() ?:(

Marten Deinum
Dec 7th, 2007, 04:26 AM
The errorcode and exception getmessage arenīt related. So I donīt see how you want to retrieve-differentiate betweeon different error codes.

qualle
Dec 7th, 2007, 09:39 AM
I'll try to explain it again:
If there is an Exception in a Web Application, you get a Page with a lot information.
The main information tells you for example: HTTP STATUS 500.
Then get you more information as:
nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:487)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:430)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690) .....

My question was, if there is a posibility to find the STATUS: 500 inside of my controller, in this case from
public class MY_Exception implements HandlerExceptionResolver{ ........}.

Any Ideas? or there isn't a way ?

benbertola
Dec 14th, 2007, 01:39 PM
The code 500 you are seeing is actually an HTTP Status Code telling the browser that a server side exception occurred. All Exceptions on the server side will by default return a 500 error.

http://www.w3.org/Protocols/HTTP/HTRESP.html