• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

throw null

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following code compiles successfully

I thought all exception classes must inherit from Throwable... well, it wasn't, so
1. are there any other "exceptional" exception class like "null"?
2. what "null" really is?
3. but why do

result in compilation error?
[ January 01, 2003: Message edited by: Aaron Anders ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1st thing -- null is not a class (and just as a hint -- you REALLY need to understand null before you take the exam). The definition from Kathy and Bert's Certification book is "A null value means that the reference variable is not referring to any object on the heap."
2nd thing -- try compiling your code again... it doesn't compile. I get the following error:
C:\blah>javac confusing.java
confusing.java:7: unreported exception <null>; must be caught or declared to be thrown
throw null;
^
1 error
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jessica,
Thats a good explanation for null.But , What is the difference between
Object o; // ??
Object o1=null; //A reference variable not referring to any object in the heap
Thanks in advance.
[ January 01, 2003: Message edited by: Salim Mohamed ]
 
Aaron Anders
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2nd thing -- try compiling your code again... it doesn't compile. I get the following error:
C:\blah>javac confusing.java
confusing.java:7: unreported exception <null>; must be caught or declared to be thrown
throw null;
^
1 error


but I compile with "javac Exceptional.java" without any error... (I'm using JDK 1.4.1_01)
[ January 01, 2003: Message edited by: Aaron Anders ]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Anders:
but I compile with "javac Exceptional.java" without any error... (I'm using JDK 1.4.1_01)


ahhhh -- I'm using JDK 1.3.1_03
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That "throw null" code works on jdk1.4 and not previous versions.
So my problem is ,
1. should we study for exam using jdk1.4 or not?
2. and where can we find list of such difference between 1.4 and previous versions.
Thanks
 
Aaron Anders
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anup Katariya:
That "throw null" code works on jdk1.4 and not previous versions.
So my problem is ,
1. should we study for exam using jdk1.4 or not?
2. and where can we find list of such difference between 1.4 and previous versions.
Thanks


one more question: I think SCJP 1.4 is based on JDK 1.4... or not?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one more question: I think SCJP 1.4 is based on JDK 1.4... or not?
The 1.4 exam is indeed based on Sun's J2SE 1.4
 
reply
    Bookmark Topic Watch Topic
  • New Topic