10.1.4 Checked and Unchecked Exceptions (Web hosting comparison) Java exceptions can
10.1.4 Checked and Unchecked Exceptions Java exceptions can be separated into two distinct groups: checked and unchecked. A checked exception signals an abnormal condition that the client must handle. All checked exceptions must either be caught and handled within the calling method or be declared in the throws clause following the method signature. This is why they are called “checked.” The compiler and the JVM will verify that all checked exceptions that can occur in a method are handled. The compiler and JVM don’t care if unchecked exceptions are ignored, because these are exceptions that the client usually cannot handle anyway. Unchecked exceptions, such as java.lang.ClassCastException, are typically the result of incorrect logic or programming errors. The determination of whether an exception is checked or unchecked is based simply on its location in the exception hierarchy. All classes that are descendants of the java.lang.Exception class, except for subclasses of RuntimeException , are checked exceptions; the compiler will ensure that they are either handled by the method or listed in the throws clause. RuntimeExceptionand its descendants are unchecked exceptions, and the compiler will not complain about these not being listed in a throws clause for a method or being handled in a try/catch block. This is why they are referred to as “unchecked.” 10.1.5 Performance Impact of Exception Handling In general, wrapping your Java code with try/catch blocks doesn’t have a significant performance impact on your applications. Only when exceptions actually occur is there a negative performance impact, which is due to the lookup the JVM has to perform to locate the proper handler for the exception. If the catch block for the exception is located in the same method, the impact is not so bad. However, the further down the call stack the JVM has to go to find the exception handler, the greater the impact becomes. This is why you should use a try/catch block only for error conditions. You should never use exceptions for things such as controlling program flow. The following use of a try/catch block is probably fine, but it’s getting very close to improper use of exception handling: Double basePrice = null; String basePriceStr = request.getParameter( “BASE_PRICE_AMOUNT” ); // Use a try/catch to make sure the value is a number try{ basePrice = Double.valueOf( basePriceStr ); }catch( NumberFormatException ex ){ // The value could not be converted to a valid Double; setthe default basePrice = ApplicationDefaults.DEFAULT_BASE_PRICE; } The previous code fragment shows a try/catch block determining an error condition and taking corrective action. The error condition is an invalid price value, and the corrective action is to assign a default value. There are other ways to determine whether a string is a valid Double value, but using this approach is fairly popular. Fortunately, the exception handler is located in the same method, and the JVM doesn’t incur a large penalty for this occurrence.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.