我正在React Native上使用Realm Database。在我的模型架构ID字段中为必填字段。当id字段未定义时,Realm会返回异常,并且不会添加数据。为什么Realm在try catch中不返回异常?
模型架构:
export default class ServicesModule {
cache = {};
}
ServicesModule.schema = {
name: "ServicesModule",
primaryKey: "id",
properties: {
id: "int",
title: "string?"
}
};
插入数据:
try {
return new Promise((resolve, reject) => {
realm().write(() => {
resolve(realm().create("ServicesModule", {title: 'Test exception'}, true));
});
});
} catch(e) {
console.error(e.message);
}
答案 0 :(得分:0)
可能是因为您的承诺没有被拒绝。尝试:
package ee.sims;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class CalederFfdriver {
private static WebDriver driver = new ChromeDriver();
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"/Users/owner/desktop/chromedriver");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.path2usa.com/travel-companions");
driver.findElement(By.cssSelector("#travel_date")).click();
List<WebElement>dates =driver.findElements(By.cssSelector(".day"));
System.out.println(dates.size());
WebElement navigator =driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='next']"));
while(!driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='datepicker-switch']")).getText().contains("April"))
driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='next']")).click();
for(int i=0;i<dates.size();i++) {
String text=dates.get(i).getText();
if(text.equalsIgnoreCase("23"))
dates.get(i).click();
}
}
final boolean retrying (By by) {
boolean result = false;
int attempts = 0;
while(attempts < 2) {
try {
driver.findElement(By.xpath("//*[@class='datepicker-switch']")).click();
result = true;
break;
} catch(StaleElementReferenceException e) {
}
attempts++;
}
// note that i replaced "return;" here because it was a syntax error
return result;
}
}