gpt4 book ai didi

java - json 的异常 - JavaME

转载 作者:行者123 更新时间:2023-12-01 15:57:05 28 4
gpt4 key购买 nike

我正在用java me为黑莓编写一个程序。

无论如何我可以将捕获的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();
}`

最佳答案

Is there anyway I can write java exception caught into a json format?

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

What about if I have three different types of exceptions? How do I match the filename and the exception?

try{
//something
}catch(MyExceptionOne ex){
//do something
}catch(MyExceptionTwo ex){
//do something different
}catch(MyExceptionThree ex){
//do something very different
}

关于java - json 的异常 - JavaME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4860236/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com