Just-In-Time Compilers


As you begin to write larger and more complex applications, the possibility of errors will exist. Well, your code will contain errors, and debugging them may not always be easy. In this chapter, we will cover some of the errors you can expect to experience as well as the various options available for finding their cause. First let's look at some of the error types you are likely to see.

Error Types

Four types of errors are encountered in the development and execution of a software application: compiler parse errors, run-time errors, logic errors, and user errors. Of these errors, the first three are under your control as a developer. Let's examine how Resin works with you to identify these error types.

Compiler Parse Errors

Consider the following JSP code as an example of compiler parse errors:

 <%     String username = null;     out.print("The user's name is " + username + "<BR>");     out.print("Calculation of 5 / 0 = ", 5/0 | "<BR>");     if (1 < 2)       write("1 > 2");     else       out.print("1 < 2"); %> 

When you browse to a page containing this JSP code, you get the output shown in Figure 12.1.

click to expand
Figure 12.1: Compiler parse errors.

In Figure 12.1, the Resin server has attempted to compile the JSP code so it can be executed. Unfortunately, the code contains a couple of errors, so the Resin server returns a 500 Servlet Exception error and a listing of the code with possible error locations. The first error results because the code uses a comma (,) character instead of a plus (+) to concatenate values in a print statement. The second error is the use of the statement write instead of print (the system doesn't know about a write command). Once you fix these two errors, the code will execute.

Run-time Errors

Once your code executes, you may encounter another error type: a run-time error. A run-time error occurs when an error is found in the executing code. Figure 12.2 shows the run-time error information produced by the example JSP.

click to expand
Figure 12.2: Example run-time error.

If you look at the example JSP code, you will see that one of the out.print lines includes code to divide 5 by 0; this code causes an error because you cannot divide by zero. The Resin server returns to the client a 500 Servlet Exception error along with a stack dump showing where the error occurred. The first line of the dump shows that the error occurred on line 7 of the errortest.jsp page.

Logic Errors

Once you fix the division-by-zero error, you can reload the page. As you can see in Figure 12.3, the pages executes successfully. Unfortunately, there is a problem with the output.

click to expand
Figure 12.3: Logic error example.

The output appears to be correct, but the original JSP includes a comparison with an equation (1 < 2)—and the output is (1 > 2). This an example of a logic error, which is by far the hardest error type to recognize and find in the application code. The Resin server and the Java compiler are completely unable to determine whether this result is an error.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net