想象一下,我有以下代码将记录插入Apache Jena数据库(TBD):
private fun createPersonLogic(ds: Dataset, email: String, nick: String) {
ds.begin(ReadWrite.WRITE)
val model = ds.defaultModel
val uuid = UUID.randomUUID()
val uri = "http://mycompany.com/data/p-${uuid}"
val person = model.createResource(uri)
person.addProperty(VCARD.EMAIL, email)
person.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.NICKNAME, nick))
ds.commit()
ds.end()
}
在执行model.createResource
和ds.commit
期间处理错误的正确方法是什么 - 如下面的代码片段或其他方式?
private fun createPersonLogic(ds: Dataset, email: String, nick: String) {
try {
ds.begin(ReadWrite.WRITE)
val model = ds.defaultModel
val uuid = UUID.randomUUID()
val uri = "http://mycompany.com/data/p-${uuid}"
val person = model.createResource(uri)
person.addProperty(VCARD.EMAIL, email)
person.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.NICKNAME, nick))
ds.commit()
}
catch (throwable:Throwable) {
// react to the error
}
finally {
ds.end()
}
}
答案 0 :(得分:0)
我们怎么可能知道你的应用程序对这种失败的正确答案是什么?!
说真的:这是您的项目,您的应用程序,您的要求。你必须清楚这类问题意味着什么给你。
尽管如此,"泛型"是: