如何在Android Exceptions上最佳地执行优雅降级

时间:2014-01-20 06:36:53

标签: android exception-handling

我一直想知道是否有一种优雅的方式来处理至少通知用户的异常,并确保应用程序不会关闭

这就是我目前的做法异常处理您能否建议有更好的模式。

            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();
        }

0 个答案:

没有答案