• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error detection in Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
matrix
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Travis Benning
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic