This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ExceptionInInitializerError question

 
Ranch Hand
Posts: 167
1
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in ethuware, I faced two questions that confused me:





I cannot understand why in the first case it does not compile. Shouldn'it it throw an exception in initializer error like the second example?
 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ioanna Katsanou wrote:
I cannot understand why in the first case it does not compile. Shouldn'it it throw an exception in initializer error like the second example?



Section 8.7 of the JLS requires that static initializers can complete normally. The first case does not, and hence, fails to compile.

Section 14.21 of the JLS are the tests to determine whether code is reachable. This is also the test for completing normally.... and there are special cases for the if/then to allow for conditional code. Hence, it is possible for the if/then to complete normally, hence, the second case compiles.

https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.7
https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.21

Henry
 
Ioanna Katsanou
Ranch Hand
Posts: 167
1
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved thanks !!!
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic