Using try/catch for preventing app from crashes

前端 未结 14 1845
你的背包
你的背包 2021-01-30 03:37

I have been working on an Android app which uses try/catch frequently to prevent it from crashing even on places where there is no need. For example,

A view

14条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 04:12

    It's bad practice to use catch(Exception e){} because you're essentially ignoring the error. What you probably want to do is something more like:

    try {
        //run code that could crash here
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    

提交回复
热议问题