Java 錯誤(Error)與例外(Exception)的區別如下。
Error
Error是非預期的錯誤,無法也不必try catch,通常是因為應用程式執行環境造成的錯誤,例如OutOfMemoryError,StackOverflowError
Exception
Exception是可預期的錯誤,需要try catch,通常是因為應用程式本身的錯誤,例如NullPointerException,ClassCastException,IndexOutOfBoundsException,IOException。
沒有留言:
張貼留言