补充一点:这个DataTable是跟DataGrid关联的,在DataGrid里输入数据,按键到下一行时,DataGrid会自动往DataTable里增加一个新行。不知道这个引发的异常会发送到哪一段代码里?

解决方案 »

  1.   

    不知这样对不对:
    你可以在RowChanging事件中调用一个方法来添加行。而截获也是在这个方法里。不知可以不
      

  2.   

    不成的,RowChanging就发生在添加行即将完成的时候,但还没有完成添加,我说的异常就是在这个事件里手工引发的(本来是没有异常的),但不知道引发后它传去哪了。
      

  3.   

    try{
    throw myException;//throw exception here
    }
    catch(MyException e)
    {
    //do something here;
    }
      

  4.   

    try{
    ……
    throw myException
    }
    catch(MyException e)
    {
    Response.write(e);
    }
      

  5.   

    上面两位写的都没有实际用处,既然我抛出了一个异常,就肯定不会在当前代码段里处理了,否则既无效率,抛出异常也影响性能,直接处理会更好一些。
    在RowChanging事件里处理了异常以后,异常就没有了,就不会阻止DataTable继续添加该行数据。
      

  6.   

    RowChanging事件也是委托。
    真正调用它的是在
    OnRowChanged这个函数中。我觉得你可以重写OnRowChanged这个虚函数,在里面捕捉你的异常。最后在调用一下基类的得OnRowChanged。
      

  7.   

    OnRowChanged函数的作用也仅仅是调用RowChanged事件,OnRowChanging函数的作用仅仅是调用RowChanging事件,在这里捕捉异常没办法影响到后续的添加行流程。
      

  8.   

    可以记住当前行oldRowIndex,如果rowchanged了,判断oldRow是否通过验证,
    如果通过,则oldRowIndex=newRowIndex,否则手动选择oldRow
      

  9.   

    qie,不符合条件的行,先添加后,再用row.delete删除不就行了
      

  10.   

    you'll have to throw the exception so add a handler to AppDomain.UnhandledException like I mentioned before. I recommend you also create a custom exception class that derives from ApplicationException (typically used for custom exceptions to give them a common, application-based base class) that you throw from the DataTable.RowChanging event handler. This way, you can easily just catch this exception in the handler for the AppDomain.UnhandledException event and handle appropriately, which is better than throwing such a oft-used exception and trying to determine where it came from and why it was thrown. 
      

  11.   

    要使用Application.ThreadException来处理这个异常。