This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

static initializer cannot pass on the checked exceptions

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all (once again )
in velmurugan notes it is given that static initializer cannot pass on the checked exceptions. they have to catch and handle them...
i am not sure what does it means.. can anybody tell me about this..
thanks in advance
bye
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where in the notes is that printed? Maybe mine is outdated...
Look in the API for "ExceptionInInitializerError", which is suited towards dealing with exceptions in static initializers. Perhaps he is simply reminding that exceptions can be thrown in static initializers.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sri,


Straight from Khalid & Rolf's book.
A static block cannot pass on checked exceptions as static blocks cannot be called explicitly, and therefore there is nothing to handle the exceptions



Example code:

If you add try, catch block then there will be no error.

Hope this helps,
Vanitha.
 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks vanitha,
now it is clear....
but there is one more point which is not very clear to me... it is that
"instance initializers can throw any exception in annonymous class"
if u can tell me about this too it will be very useful...
 
brevity is the soul of wit - shakepeare. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic