As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?
Unchecked Exception:
RuntimeException are known as unchecked exceptionsArithmeticException,NullPointerException, ArrayIndexOutOfBoundsException etcArithmeticEceeption. We can avoid them by a simple if condition - if(divisor!=0). Similarly we can avoid NullPointerException by simply checking the references - if(object!=null) or using even better techniques
Error:
Error refers irrecoverable situation that are not being handled by try/catch
Example: OutOfMemoryError, VirtualMachineError, AssertionError etc.
This question may also be helpful in this context - Runtime/Checked/Unchecked/Error-Exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With