我一直想知道是否有一种优雅的方式来处理至少通知用户的异常,并确保应用程序不会关闭
这就是我目前的做法异常处理您能否建议有更好的模式。
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);;
User user = null;
try {
user = mapper.readValue(cmsg.message(), User.class);
} catch (JsonParseException e) {
Log.e("User Parsing", "JsonParseException in deserializing user",
e.getCause());
} catch (JsonMappingException e) {
Log.e("User Parsing", "JsonMappingException in deserializing user",
e.getCause());
} catch (IOException e) {
Log.e("User Parsing", "IOException in deserializing user",
e.getCause());
}
finally{
Toast.makeText(activity, globalError, Toast.LENGTH_LONG)
.show();
activity.recreate();
}