This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error detection in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error detection in Java" Watch "Error detection in Java" New topic

Error detection in Java


Joined: Jan 21, 2002
Posts: 2
How can one predict whether an error in code is detected during Compilation or during run time.
Are there any rules of thumb or any guidelines defining as to when an error is detected?
Please explain this, are there any articles/resources discussing this in detail?
Thanks in Advance.

Travis Benning
Ranch Hand

Joined: Jan 24, 2002
Posts: 74
All errors that appear when you use the compiler are Compilation problems.
If you compile correctly, and then run your program, and either you get a runtime, or logic errors, those would be Runtime errors (and logic errors i guess)
Use try/catch blocks to catch and possibly throw your own exceptions.
Otherwise, Compilation errors have to be fixed with trial and error i think.
Ranch Hands, correct me if I'm wrong please
Hope this helped a little

Sun Certified Programmer for Java 2 Platform

Joined: Jan 21, 2002
Posts: 2
Thanks Travis,
But by looking at the code, even before compiling, how can one make out where an error will be detected? I came across some questions where in certain piece of code is given and one has to predict whether the errors are detected during compilation or during runtime.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!

Travis Benning
Ranch Hand

Joined: Jan 24, 2002
Posts: 74
one easy way to predict is to see if any of your numberic formula are ever divided by zero.
If you find one, it can throw an ArithmeticException exception. By enclosing the formula in a try/catch block, you can take care of the error ahead of time, in case it happens.
Also, if any of your variables haven't been initialized, they might throw an exception (NullPointerException maybe. not sure),
If any of your arrays go past there limits
(array[] with 2 objects, but you try and call the object located at array[2], which doesn't exist), it could throw ArrayIndexOutOfBounds exception, i think.
Hope this helps
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
The essence of your question is what the SCJP test is all about! It's really a matter of learning the java language, syntax, and grammar, and writing a lot of sample code, and becomming familiar with how things. work.
It's a matter of experience. The more you work with java, the more you can predict the kinds of things you are talking about.

SCJP 1.4
jQuery in Action, 2nd edition
subject: Error detection in Java
Similar Threads
compilation problem
Compiler bug
TCP/IP SOCKETS T4Agent.sendRequest() OutputStream.flush() Broken pipe * 0