Topic
  • 2 replies
  • Latest Post - ‏2011-11-23T20:33:35Z by VQBV_Anjib_Mulepati
VQBV_Anjib_Mulepati
VQBV_Anjib_Mulepati
2 Posts

Pinned topic Catching and displaying exception from the JAVA

‏2011-11-16T19:43:02Z |
Hi All,

I am trying to display the helpful message to the user when error occur.

a) I have exception catching in Java as follow
CODE
AgencyDAO a = new AgencyDAO();
try {
a.updateAgency(agencyId, newAgencyCode, newAgencyName);
} catch (DAORuntimeException e) {
String message = "My Custom message";
request.setAttribute("GROUPING_EXCEPTION", new Exception(message, e));
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
}
return null;
[/CODE]

b) AJAX call from JSP is as follow
CODE
$.ajax({
url: "updateAgency.do",
data: {
id: nRow.id,
new_code: jqInputs[0].value,
new_name: jqInputs[1].value
},
success: function() {
alert("Successfully updated.");
oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
},
error: function(xhr, ajaxOptions, thrownError) {
alert("Update failed.");
restoreRow(oTable, nRow);
}
})
[/CODE]

So in case of update fail I am getting message "Update failed." from alert. I want to show "My Custom message".

In Firebug when I check the response I am getting
CODE
<html><head><title>Apache Tomcat/6.0.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body>

HTTP Status 500 - My Custom message

<HR size="1" noshade="noshade">

type Status report

message My Custom message

description The server encountered an internal error (My Custom message) that prevented it from fulfilling this request.

<HR size="1" noshade="noshade">

Apache Tomcat/6.0.20

</body></html>
[/CODE]

Is there any method ow way I can get that custom message when AJAX call fails?

Thanks
Anjib
Updated on 2011-11-23T20:33:35Z at 2011-11-23T20:33:35Z by VQBV_Anjib_Mulepati
  • seohulu
    seohulu
    4 Posts

    Re: Catching and displaying exception from the JAVA

    ‏2011-11-22T16:28:48Z  
    you need to post your log from web container here, a lot of thing can caused 500 error.
    --
    Acoolme is an Online Marketing Software Platform And Social Community
  • VQBV_Anjib_Mulepati
    VQBV_Anjib_Mulepati
    2 Posts

    Re: Catching and displaying exception from the JAVA

    ‏2011-11-23T20:33:35Z  
    • seohulu
    • ‏2011-11-22T16:28:48Z
    you need to post your log from web container here, a lot of thing can caused 500 error.
    --
    Acoolme is an Online Marketing Software Platform And Social Community
    I am not worried about 500 error itself. I am trying to convert this 500 error message to some meaningful one.
    In firebug console in response it have message "Duplicate code". I want to extract that and display.