Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can synchronized( someObj ) ever throw an exception?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that object.wait() can throw an exception (IllegalMonitorStateException or InterruptedException) can synchronized ever do the same?

For example:



What is that synchronized line in byte code?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to synchronize on a null reference, a NullPointerException will be thrown. (See JLS - 14.19.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic