Tag Archives: exception

Overriding methods cannot throw new/wider checked exceptions

Java programming rule: An overriding method cannot throw checked exceptions that are new or wider than those thrown by the overridden method. However, an overriding method can throw runtime exceptions (RuntimeException) not thrown by the overridden method. In the following example, Dog … Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment

java.io.RandomAccessFile and checked exceptions

This example program demonstrates how to use the RandomAccessFile class to open a file in read-only mode and get the file length measured in bytes.  The code uses try, catch, and finally blocks to catch checked exceptions. Notice how we check … Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment

Checked exceptions, errors, and runtime exceptions

An exception in Java means “an exceptional event” that can interrupt the expected flow of a program. This can cause the program to crash or do something unexpected. Exceptions may be grouped into checked and unchecked exceptions. Checked exception — … Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment