In going through these mock exams, I find a lot of questions dealing with compile time errors and run time errors. What is a general rule of thumb for when to expect a compile time error and when to expect a run time error -Dale ------------------ What's this H2SO4 doing in my fridge?? ( thud )
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
I have a hard time with determining if it would be a compile time error or a run-time error. I do know that the compiler tries to find as much as it can. But, many things for example, things that have to do with the live object being used can only be determined at run-time.
Joined: Nov 02, 2000
That's exactly my point. I'd like to find a general rule to figure out if something would generate a run-time error or a compile-time error. -Dale ------------------ What's this H2SO4 doing in my fridge?? ( thud )
Depends on the superclass of the Exception that is being thrown. Check the API for the Exception you are wondering about to see whether it inherits from RuntimeException or not. If it does not, it is a compile-time Exception.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Compile time errors - caused by errors in syntax or breaking rules that a, for lack of a better term, "well-formed" java program should follow. Things like illegal type conversions, typos, missing parenthesis, redeclaration of variables, etc. that the compiler can determine to be incorrect during compile time. Can usually be traced back to one line in particular. Runtime errors are usually related to logic errors. The syntax may be correct and the error may be thrown at a particular line of code, but the cause may be due to the logic encompassed by several lines of code. Things like off-by-one loop errors, improperly casting objects, invoking a method on a null object reference would produce runtime errors. A clarification to what Marilyn said above: All exceptions occur at runtime. The difference is that the compiler will complain about code that does not explicitly catch Checked exceptions. Junilu