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

Fre*_*Boy 4 .net asp.net objectdatasource

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

问题是我没有控制它.呈现页面时,ObjectDatasource直接调用select方法,并直接抛出未处理的异常.

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

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

还有其他选择吗?

Kir*_*ill 9

查看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;

    }
}
Run Code Online (Sandbox Code Playgroud)