例如,我有以下构造函数,我的一个要求是当构造函数为null时使构造函数崩溃。
public Test(String test){
if(test != null){
anyVariable = null;
}
}
测试用例使用以下内容: catch(java.lang.Exception e)
答案 0 :(得分:1)
当它为null时抛出异常:
if (test == null) {
throw new Exception();
}
如果您需要留言,请执行以下操作:
if (test == null) {
throw new Exception("test cannot be null");
}