Object Integrity & Security: Error & Exceptions

In this case, when the the code encounters the divide by zero, the application does not catch it and the exception finds its way to the run-time and terminates the application ungracefully as seen in Figure 1.

RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.

One of the important issues here is defined in the second sentence. For a RunTimeException, you do not have to do any preparation for it in your code. In short, this means that the compiler does not require you to provide code to catch a possible occurrence of a RunTimeException. However, this does not mean that you shouldn't—it is just that the compiler will not enforce this.

Note that in this case the IOException does not inherit from RunTimeException; it is a direct descendant of Exception. In the case of IOException, the compiler will force you to prepare for this in the sense that you will have to provide code to catch or throw the IOException. To illustrate, consider the following code in Listing 2:

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.

Thanks for your registration, follow us on our social networks to keep up-to-date