Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can synchronized( someObj ) ever throw an exception?  RSS feed

 
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.)
 
I love a good mentalist. And so does this tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!