I have a Spring controller from where I'm returning a String. Basically I'm using JSONObject and JSONArray and finally making a String and returning it. Like:
@RequestMapping(value = "getValue")
    public @ResponseBody
    String getValue(){
    JSONObject jassonObject = new JSONObject();
    JSONArray jassonArray = new JSONArray();
    jassonObject.put("mykey",jassonArray);
    And finally:
    return jassonObject.toString();
}
But suppose while generating this JSONObject if I get any exception I want to return that exception message. That is :
try {
JSONObject jassonObject = new JSONObject();
JSONArray jassonArray = new JSONArray();
jassonObject.put("mykey",jassonArray);
return jassonObject.toString();
} catch(Exception ex) {
return the exception?
}
My question is that how to return this exception value properly as error and get this properly from ajax call error function?
 
    