• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Twist in Tale 7.5

 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code below is from Mala Gupta's book, Twist in Tale question. The very last line is supposed to generate a NullPtrException, and i do see the NullPtrException when i use the try/catch block i have shown. But when i remove the try/catch block, and just have that line by itself, i do not see a NullPtrException in the Netbeans output window. Why is that ?



The output of the above code is as expected .....
Starting TIT 7.5 nullptrexception
dell
null
IBM
null
[[Ljava.lang.String;@e83912
going to dereference null
caught dereference null : java.lang.NullPointerException

But, the output of code without the try/catch block (the code last line by itself) is below.....
Starting TIT 7.5 nullptrexception
at initprocess.InitProcess.main(InitProcess.java:205)
dell
null
IBM
null
[[Ljava.lang.String;@e7b241
going to dereference null
Java Result: 1

Is any exception indicated with Java Result: 1 in the output window of Netbeans ? (that is my guess).

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried running it from a command line ? Netbeans may be swallowing the exception - you need to look at the Netbeans documentation to find out if this is the case.
This is one of the reasons beginners are recommended not to use IDEs to start with - you don't know when an unexpected result is due to java or the IDE.

By the way - your comment on line 13 is incorrect - there is no dereferencing of any element of the laps array on that line. There is on line 18, where you are trying to dereference the element at position 3,0.
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is dereferencing, according to the book i am reading (Mala Gupta, OCA exam book). You can look up Twist in Tale 7.5, if you have the book. First of all, since array laps is 2 dimensional, there will be a dereference at laps[2] in order to get to the second dimension. I didn't intend to put that comment into this thread, but made the comment for myself (hence the C terminology).

I was pretty sure that output by Netbeans "Java result = 1" indicated an abnormal termination of the program, but was lazy to go through Netbeans doc. - my mistake.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic