如何处理异常被抛出的ObjectDataSource的选择方法是什么? [英] How to handle an exception is thrown by Select method of ObjectDatasource?

查看:170
本文介绍了如何处理异常被抛出的ObjectDataSource的选择方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到一个ObjectDataSource选择的方法,这种方法可能会抛出异常,我不知道该如何处理呢!

I have a Select method connected to an ObjectDatasource, this method might throw an exception and I don't know how to handle it!

问题是,我没有控制它。当呈现页面时则选择方法是直接由ObjectDataSource控件和未处理的异常被称为是直接抛出。

The problem is that I'm not controlling it. When the page is rendered then the select method is called directly by the ObjectDatasource and an unhandled exception is thrown directly.

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

On the other hand, I don't want to make it return empty collection if it has a problem because the collection might be empty without problems.

所以,我在哪里可以处理这个异常?

So, where can I handle the exception?

任何其他的选择吗?

推荐答案

只看ObjectDataSource控件的EventArgs的。应该有一个e.Exception和放大器; e.Results,你可以为你的选择的成功/错误查询。

Look at the eventargs on the ObjectDataSource. There should be an e.Exception & e.Results that you can query for the success/error of your select.

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;

    }
}

这篇关于如何处理异常被抛出的ObjectDataSource的选择方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆