gpt4 book ai didi

.net - ObjectDatasource的Select方法抛出异常如何处理?

转载 作者:行者123 更新时间:2023-12-04 22:50:32 24 4
gpt4 key购买 nike

我有一个 Select 方法连接到 ObjectDatasource,这个方法可能会抛出异常,我不知道如何处理它!

问题是我没有控制它。当页面呈现时,对象数据源直接调用 select 方法,并直接抛出未处理的异常。

另一方面,如果有问题,我不想让它返回空集合,因为集合可能是空的,没有问题。

那么,我在哪里可以处理异常?

还有其他选择吗?

最佳答案

查看 ObjectDataSource 上的 eventargs。应该有一个 e.Exception & e.Results 您可以查询选择的成功/错误。

protected void MyOds_Selected (object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
// handle exception here.
...
//tell the ObjectDatasource that the exception is handled
//and don't rethrow it.
e.ExceptionHandled = true;

}
}

关于.net - ObjectDatasource的Select方法抛出异常如何处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6822308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com