捕捉整个 Android 应用程序中的特定异常

huangapple 未分类评论48阅读模式
英文:

Catching specific exception on entire android app

问题

在我的安卓应用中,几乎每个活动都会进行网络请求,我的目标是对401状态码(未授权)做出正确反应 - 将用户重定向到登录界面。

我正在使用Volley,所以我应该在每个活动中捕获VolleyError异常并分别对其进行处理,还是有可能在整个应用程序中捕获该错误,以减少代码量呢?
什么才是正确的方法?

英文:

In my android app almost every activity does network requests, my goal is to properly react to 401 code(unauthorized) - redirect user to login screen.

Im using volley, so should I catch VolleyError exception in every activity and react to it separately - or is there possibility to catch that error on entire app so there's less code?.
What would be the proper approach?

huangapple
  • 本文由 发表于 2020年6月5日 21:03:19
  • 转载请务必保留本文链接:https://java.coder-hub.com/62216001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定