Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Please explain reason for the wording of this error message

 
Greenhorn
Posts: 3
Mac OS X Ruby Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 4801
50
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic