Differences between Runtime/Checked/Unchecked/Error/Exception

前端 未结 8 950
走了就别回头了
走了就别回头了 2020-11-27 05:17

What are the Runtime exceptions and what are Checked/Unchecked Exceptions and difference between Error/Exception.Why these many types? Instead Java may simply follow a simpl

8条回答
  •  旧时难觅i
    2020-11-27 05:45

    Exceptions are two types in java:
    
    1. **Checked Exception: The exceptions which are checked by compiler. 
    

    For example: we you are performing operation with file, then compiler will ask you to handle IOException either by try-catch block or throws keyword.

    2. Unchecked Exception: The exceptions which are not checked by compiler at run time. 
    

    For example: If you are performing operation on an object without creating it; in this case you'll get NullPointerException.

提交回复
热议问题