• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please explain reason for the wording of this error message  RSS feed

 
Ronald Otto
Greenhorn
Posts: 3
Linux Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I erroneously wrote the following crap in my -block:



The correct way to write it is

System.out.println("EXCEPTION "+e.getClass());

Of course, the compiler complained about my code, but I found it interesting, how it complained:



The error message says, that the symbol e was not found. How come? Of course, e is a known symbol here (and if I replace the incorrect class by the correct getClass(), I don't get a compiler error anymore.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

My explanation may not be the best so I give it a try.

When you use ".class" (with the dot) the compiler/JVM is really looking for that class file/bytecode.

So in your case, the compiler is looking for the class called "e" in your project or Java API, which there isn't one. "e" is a variable, the compiler doesn't know you are referring to the "Exception.class" if you do "e.class".

Therefore using "e.getClass()" will resolve that to the Exception.class
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I just suggest that, instead of printing the class and message, you do:

You will miss a lot of info if you don't do that, including the exact line that is causing your exception, and any exception chains.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:When you use ".class" (with the dot) the compiler/JVM is really looking for that class file/bytecode.

A couple of things:
1. It can't be the JVM, because it's a compiler error.
2. It can't be looking for a class file because it may not be compiled yet.

But you're absolutely correct that it's looking for something - a Class name.

@Ronald: I agree with you; the message is badly worded - although that may have something to do with the way that it checks these things.

But not being a compiler writer, it's all I can offer.

Winston

PS: Welcome to JavaRanch, Ronald.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!