aspose file tools*
The moose likes Java in General and the fly likes Based on the message, what kind of failure is this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Based on the message, what kind of failure is this?" Watch "Based on the message, what kind of failure is this?" New topic
Author

Based on the message, what kind of failure is this?

John Batista
Greenhorn

Joined: May 22, 2011
Posts: 20
I made a mistake on purpose to see what the compiler would throw at me. In this case, I omit the variable that's called inside a method:



and in the main class


and I got


I'm using eclipse and surprisingly, only the T class that has those little red x mark at tryMe method pointing that I made a mistake there. But the code in Main.java is clean. No red x mark anywhere. ut then after "Run as Java Application", I get the failure (which I'm expecting). Now, Is this an Error (because of java.lang.Error) or exception (because the failure text also mentioned "Exception in thread..."). If exception, is it runtime or checked? Or is it just a compile error and none of the failure type I mentioned before? thanks
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

Hi John,

Did you run this code after declaring public String name(line 5 - class T) as a comment //?
If you are it's a compile error because syntax error at line 5 in class T. Then remove // on line 5 in class T and try to run.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hard to say. When I try to compile Main.java my compiler says:


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

Michael, did you remove // in class T?
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Udara Amarasinghe wrote:
Michael, did you remove // in class T?

I did. Does not make any difference to the compiler; maybe it contributes to an IDE bug, but a comment shouldn't affect the IDE runtime verifier either.
John Batista
Greenhorn

Joined: May 22, 2011
Posts: 20
Different error message? this is unexpected. Did you run from console using java command? I run this from eclipse.
@Udara: so it's compile error as in Error type? not exception? I'm still a bit confused.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I did run it from a console, as I figured the error you received must have something to do with how the IDE editor and verifier are interacting.
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

John Batista wrote:Different error message? this is unexpected. Did you run from console using java command? I run this from eclipse.
@Udara: so it's compile error as in Error type? not exception? I'm still a bit confused.

In here compiler errors means just errors that appears in the comply time because of inappropriate syntax, try to comply not java files or mistakes like that...

But there is runtime errors that throws by JVM when found unrecoverable errors. And they are derived from java.lang.Error class.
And Exceptions are thrown by the program. Programs can recover from those. And they are derived from java.lang.Exception class.

these tutorial will helps you tutorial.

Michael Ernest wrote:I did run it from a console, as I figured the error you received must have something to do with how the IDE editor and verifier are interacting.

I didn't try it with eclipse IDE. So perhaps.
John Batista
Greenhorn

Joined: May 22, 2011
Posts: 20
so, how do one predict what kind of failure a code will give? Is it possible to predict that it's gonna be compile error or exception (and if exception, will it be checked or unchecked)? or do I have to memorize these? because there are exam questions that will ask about the result of an execution block. thanks
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

Hi, Ranch

Its exception of type java.lang.RuntimeException

while compiling compiler try to look for the variable "name" which you are printing. It cannot find the variable name becoz you have commented (for testing i suppose). It throws a runtime exception. its not a forced exception........ But its a compilation error only

look what result i got when i run it in the NetBeans

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

Hi, Ranch

Its exception of type java.lang.RuntimeException

while compiling compiler try to look for the variable "name" which you are printing. It cannot find the variable name becoz you have commented (for testing i suppose). It throws a runtime exception. its not a forced exception........ But its a compilation error only

look what result i got when i run it in the NetBeans

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code

try to write both classes in same file
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

John Batista wrote:so, how do one predict what kind of failure a code will give? Is it possible to predict that it's gonna be compile error or exception (and if exception, will it be checked or unchecked)? or do I have to memorize these? because there are exam questions that will ask about the result of an execution block. thanks

Yes you have to keep them in memory. But it's very easy thing because if you can keep basic theories of the java language than definitely you will be able to determine what going on in this code and whether it makes errors or not. I suggest you to do more particles and try to understand and keep in memory those basic theories.

vinayak jog wrote:Its exception of type java.lang.RuntimeException

Vinayak, that runtime exception appears because you run this code in NetBeans. It's a IDE side runtime exception. If you compile this code as the default way(using javac command on a command prompt) without a IDE. You will get compilation failure without any thrown exception types of java.lang.Exception or Error types of java.lang.Error.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Based on the message, what kind of failure is this?