json-JavaME的异常

json-JavaME的异常,java,blackberry,java-me,Java,Blackberry,Java Me,我正在用JavaME为blackberry编写一个程序 我是否可以将捕获到的java异常写入json格式?我该怎么做?我应该考虑什么?谢谢 会是这样吗 catch (IOException e) { String IOExceptionMsg = "description:Warn exception: OSError. Exc_type: :Caught IOException:" + e.toString() + ",filename: " + i

我正在用JavaME为blackberry编写一个程序

我是否可以将捕获到的java异常写入json格式?我该怎么做?我应该考虑什么?谢谢

会是这样吗

catch (IOException e) {
    String IOExceptionMsg = 
        "description:Warn exception: OSError. Exc_type: :Caught IOException:" + 
        e.toString() + ",filename: " + imageName;

    out.write(IOExceptionMsg.getBytes())
} 
catch (Exception e) {
    String Exception = 
        "description: Unknown Error:Caught Exception:" + e.toString() + 
        ",filename:" + imageName;

        out.write(Exception.getBytes());
        out.flush();
}
我有这样的json格式。我如何将它们放在一起

`public String toJSON()
{
final String 
IMAGENAME = imageName,
description = "",
filename = imageName;
JSONObject outer = new JSONObject();
JSONObject inner = new JSONObject();
try {
outer.put(IMAGENAME, inner);

// Values are added to the JSONObject in pairs, label then value
inner.put(description, description);
inner.put(filename, imageName);
} catch (JSONException ex) {
ex.printStackTrace();
}
return outer.toString();
        }`
我是否可以将捕获到的java异常写入json格式

您可以捕获异常,然后提取它的消息并将其放入JSON中,以执行您需要的操作—您不能直接告诉JVM将其放入JSON跟踪中


如果我有三种不同类型的异常呢?如何匹配文件名和异常


如果我有三种不同类型的异常呢?如何匹配文件名和异常?上面的代码不是json格式。如何将其放入JSON跟踪中?您希望捕获JSONException还是希望以JSON格式获取跟踪?然后简单地以正常格式获取跟踪并从中创建JSON
try{
  //something
}catch(MyExceptionOne ex){
  //do something
}catch(MyExceptionTwo ex){
  //do something different
}catch(MyExceptionThree ex){
  //do something very different
}