• 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

Required more explantion on exmaple given in Thread.

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Here


Always thought null Pointer exception. still compiler is not taking any objection at compile time. Can any buddy explain this?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kaushik vira wrote:

Always thought null Pointer exception. still compiler is not taking any objection at compile time. Can any buddy explain this?


No reason for the compiler to complain. We are talking about unchecked exceptions here. The handle and declare rule is only for checked exceptions.

cheers
Bob
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[deleted: double post]
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


if line 1 is sifted to new position then it gives compilation error. But when it is at its original position why it is not giving error?

thanks in advance
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well when line 1 is at its original position, then there's a if condition there. So the compiler will think that NullPointerException may or may not be thrown. But if you move it below the other throw clause, then it definitely becomes unreachable, there's no way that control could reach the next statement to that throw statement. That's why the compiler complaints that the statement is unreachable. I know that the if condition will always be true so the NullPointerException will always be thrown, but the compiler for some reasons ignores that...
 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the above point.. but my expectation here was, to get some internals of java compiler.. how it`s handling this type of conditions. Can can buddy elaborate it.

 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic