11.1 Simple Exception Handling
By now we have discovered that sometimes our program doesn’t work, even though we didn’t get any compiler errors. At run time, logic errors can surface. For example, we might attempt to divide an integer by 0 or try to access the 11th element in a 10-element array. Java is a robust language and does not allow these “illegal” operations to occur unnoticed.
These illegal operations generate exceptions. Some exceptions are generated by the Java Virtual Machine, while others are generated by constructors or other methods. For example, a method might generate an exception when it detects an attempted illegal operation or an illegal parameter.
By default, when an exception is generated in an application that does not ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.