Dan*_*ann 23
你应该避免使用NullPointerExceptions:
if(someObject != null) {
someObject.doSomething();
} else {
// do something other
}
Run Code Online (Sandbox Code Playgroud)
Normally you should ensure that the objects which you use are not null.
You also can catch the NullPointerException and except using an if-condition.
try {
someObject.doSomething();
} catch(NullPointerException e) {
// do something other
}
Run Code Online (Sandbox Code Playgroud)
Normally there is a bug in your code, when a NullPointerException occurs.
Fin*_*arr 14
try {
// something stupid
} catch(NullPointerException e) {
// probably don't bother doing clean up
} finally {
// carry on as if nothing went wrong
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
61227 次 |
| 最近记录: |