This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

JVM vs Programmatically Exception  RSS feed

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I'm studying about exceptions, and I have a doubt when forcing some situation to throw ExceptionInInitializerError
using a NullPointerException.

Looking the code that follows, I'd like to know, if throwing an ExceptionInInitializeErro (JVM exception) must be
considered a programmatically exception because of the NullPointerException that causes it.

If a question like this appears on the exam, could I answer with JVM Exception even the cause being a programmatically exception?



java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at exceptions.ErroInicializacao.<clinit>(ErroInicializacao.java:5)
Exception in thread "main"


Tks!
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a programmatic exception because nowhere has a programmer written throw new ExceptionInInitializerError(). The question is whether the programmer controls the creation of the exception/error, not whether they caused it due to a mistake.

Similarly, NullPointerException is also thrown by the JVM.
 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
I was wrong when I said that NullPointerException was thrown programmatically.

The question is whether the programmer controls the creation of the exception/error, not whether they caused it due to a mistake.



So, if I throw my onwn created exception programmatically inside an initialization block getting an ExceptionInInitializerError,
caused by MyException, could I consider it as thrown programmatically?

Example:


Output:
java.lang.ExceptionInInitializerError
Caused by: exceptions.MyException
at exceptions.ErroInicializacao.getValueException(ErroInicializacao.java:10)
at exceptions.ErroInicializacao.<clinit>(ErroInicializacao.java:7)
Exception in thread "main"

Thanks
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case the MyException is thrown programmatically. The ExceptionInInitializerError is thrown by the JVM in response to an uncaught error occurring during initialisation.
 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Matthew.

I understand now.

 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!