Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception parameter

 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLS has a statement in �14.19:
Exception parameters cannot be referred to using
qualified names (�6.6), only by simple names.

What does it mean? Can someone show me a segment of code that
will violate this statement?
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A qualified name is, according to the JLS:

[a name] consisting of a sequence of identifiers separated by "." tokens

for example "this.is.my.name" is qualified, but "greg" is simple!!!
try to compile this and you will prove that the JLS is correct:
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg for the response.
I know what the qualified name is and your example explains
that. But, I still don't understand why will anyone try to use a qualified name as a parameter that way in the first place.
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, someone might be tempted to use the Exception as a
message passing mechanism. Multiple catch blocks might
catch exceptions in the usual way, with a particular
catch block for catching a particular predefined
instance of an exception.

The second class doesn't compile under JDK 1.4, with
the compiler complaining precisely at the "." delimiter
in the qualified Exception parameter.
It's not something I'd want to do, even if it were
possible. But that's one way to visualize its use (or
abuse) if not for �14.19.
Thanks,
Joe
[This message has been edited by Cindy Glass (edited September 28, 2001).]
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Joe. Yes. Who would want to do that anyway?
Now, I wonder if JLS has a statement to prohibit qualified
name for a method parameter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic