• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!