File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error detection in Java" Watch "Error detection in Java" New topic
Author

Error detection in Java

matrix
Greenhorn

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
TB


Sun Certified Programmer for Java 2 Platform
matrix
Greenhorn

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.
Keerthi
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
matrix
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!!


Dave
Travis Benning
Ranch Hand

Joined: Jan 24, 2002
Posts: 74
matrix,
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
TB
Rob Ross
Bartender

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.
Rob


Rob
SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error detection in Java