• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can assert statements be used in try-catch blocks ?  RSS feed

 
Gaia Nathan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a query. Can assert statements be used in try-catch blocks ? If so, are there any special conditions ? Thanks in advance for replies.
Gaia.
 
David Peterson
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, assert statements can be used in try..catch blocks with no "special conditions".
If an assertion fails, it throws an java.lang.AssertionError (note this is subclass of java.lang.Error rather than java.lang.Exception). Obviously under normal circumstances you should not catch assertion errors because they indicate bugs in your code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!