如何创建org.springframework.dao.DataAccessException实例? [英] How to create instance of org.springframework.dao.DataAccessException?
本文介绍了如何创建org.springframework.dao.DataAccessException实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建JUnit测试来处理DataAccessException,
I need to create JUnit test for handling of DataAccessException,
但是当我尝试时:
throw new DataAccessException();
接收:
Cannot instantiate the type DataAccessException
为什么?我能做什么?
谢谢。
Why? What can I do? Thanks.
推荐答案
DataAccessException 是一个抽象类,无法实例化。而是使用具体的类之一,例如 new DataRetreivalFailureException(这是原因)或创建自己的类:
DataAccessException is an abstract class and can not be instantiated. Instead use one of the concrete classes such as new DataRetreivalFailureException("this was the reason") or create your own:
throw new DataAccessException("this was the reason") {};
然后您将从DataAccessException派生一个匿名类。
And you get an anonymous class derived from the DataAccessException.
这篇关于如何创建org.springframework.dao.DataAccessException实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文