我在下面的服务方法中创建了company
数据。 Company
与1:1
具有CompanyType
关系,company
具有固定的一组值,并且无法插入更多值。这是一个只读表。因此,对于以下方法,我将错误的值(在DB中不存在)传递给InvalidDataAccessApiUsageException
。当然public Company create(Company company) {
Company createdCompany = null;
try {
company.setUser(userDao.findByEmail("abc@gmail.com")
.orElseThrow(() -> new AccessDeniedException("You are not authenticated for this operation")));
createdCompany = companyDao.save(company);
} catch (InvalidDataAccessApiUsageException ex) {
// will be thrown if the company-type provided doesn't exist.
// LOGGER.error(ex.getMessage());
LOGGER.error("*********************************************************");
throw new BadRequestException("Selected company type/category doesn't exist");
}
return createdCompany;
}
将在Spring之前抛出。但是我注意到catch块被调用了两次。这不是奇怪的行为吗?
2019-06-06 03:03:27 ERROR c.o.s.i.CompanyServiceImpl - *********************************************************
2019-06-06 03:03:27 ERROR c.o.s.i.CompanyServiceImpl - *********************************************************
日志
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class webdriverdemo {
public static void main(String[] args) {
// call test classes
Example1 ex1 = new Exmple1();
Example2 ex2 = new Example2();
}
}
public class Example1 {
public String baseUrl= "http://www.google.com/";
public WebDriver driver = new FirefoxDriver();
@Test
public void verifyHomePageTitle() {
// do something
}
}
public class Example2 {
public String baseUrl= "http://www.google.com/";
public WebDriver driver = new FirefoxDriver();
@Test
public void verifyHomePageTitle() {
// do something
}
}