Catch a generic exception in Java?

前端 未结 7 1155
不知归路
不知归路 2020-12-11 14:26

We use JUnit 3 at work and there is no ExpectedException annotation. I wanted to add a utility to our code to wrap this:

 try {
     someCode();         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 15:11

    Well, you could just catch Exception and rethrow if it's not an expected Exception. Though good coding practice usually dictates that the success path of code should not be defined by an Exception, so you might want to rethink your design.

提交回复
热议问题