Foxtable(狐表)用户栏目专家坐堂 → 狐爸看过来,找到狐表的重大bug


  共有3732人关注过本帖平板打印复制链接

主题:狐爸看过来,找到狐表的重大bug

帅哥哟,离线,有人找我吗?
yedaoan
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:257 积分:1971 威望:0 精华:0 注册:2012/12/20 8:21:00
狐爸看过来,找到狐表的重大bug  发帖心情 Post By:2014/2/28 15:51:00 [只看该作者]

花了很长时间来测试 Try Catch语句,原贴见(http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=46692&authorid=0&page=0&star=1)
一直以为Try Catch能捕获错并进行错误处理,实际上确实可以,问题是,如果Datatable产生的错误,结果就不一样了,出错后,仍然会执行后面的代码,而且不会跳到Catch语句。

测试1:

Try
    Dim t As Table = e.Form.Controls("Table1").Table
    t.DataTable.DeleteFor("dwmc is null")
    t.AllowAddNew=False
    t.AllowEdit=False
    t.AllowDelete=False
     MessageBox.Show(1)
    t.DataTable.Save
    MessageBox.Show(Err.Number)
    e.Form.Controls("txtZt").Text="查看状态"
    Functions.Execute("ButtonZt")
    MessageBox.Show(5)
    
Catch ex As Exception
     MessageBox.Show("关键字重复或空值,不能保存!")
End Try

结果是执行到  t.DataTable.Save 弹出错误信息,代码依然执行  MessageBox.Show(Err.Number),和    MessageBox.Show(5)

测试2:(想用On Error Goto )来代替 Try Catch,代码如下

On Error Goto Err_Msg
    Dim t As Table = e.Form.Controls("Table1").Table
    t.DataTable.DeleteFor("dwmc is null")
    t.AllowAddNew=False
    t.AllowEdit=False
    t.AllowDelete=False
    MessageBox.Show(1)
    t.DataTable.Save
    MessageBox.Show(Err.Number)
    e.Form.Controls("txtZt").Text="查看状态"
    Functions.Execute("ButtonZt")
    MessageBox.Show(5)
    Exit Sub
 
Err_Msg:
    MessageBox.Show("关键字重复或空值,不能保存!")
    Exit Sub
还是执行到  t.DataTable.Save 弹出错误信息,代码依然执行  MessageBox.Show(Err.Number),和    MessageBox.Show(5),去掉第一个Exit Sub,仍然执行后面的 Err_Msg:

测试3:

Try
    Dim t As Table = e.Form.Controls("Table1").Table
    t.DataTable.DeleteFor("dwmc is null")
    t.AllowAddNew=False
    t.AllowEdit=False
    t.AllowDelete=False
    Forms("窗口11").Open     '窗口11,并不存在,为了能出错增加了这一条
    MessageBox.Show(1)
    t.DataTable.Save
    MessageBox.Show(Err.Number)

    e.Form.Controls("txtZt").Text="查看状态"
    Functions.Execute("ButtonZt")
    MessageBox.Show(5)

Catch ex As Exception
    'Err_Msg:
    MessageBox.Show("关键字重复或空值,不能保存!")
    'Exit Sub
End Try

由于 Forms("窗口11").Open 出错在前,没有执行后面的代码直接跳到 Catch ex As Exception,为此,问题就是是出在     t.DataTable.Save ,只要有这个Datatable出错,Try Catch 就形同虚设


最后无奈之后,用了下面的代码,但这并不是我想要的


Try
    Dim t As Table = e.Form.Controls("Table1").Table
    t.DataTable.DeleteFor("dwmc is null")
    t.AllowAddNew=False
    t.AllowEdit=False
    t.AllowDelete=False
    MessageBox.Show(1)
    t.DataTable.Save
    MessageBox.Show(Err.Number)
    
    If Err.Number=0 Then
       E.Cancel=True
       Exit Sub
    End If
    e.Form.Controls("txtZt").Text="查看状态"
    Functions.Execute("ButtonZt")
    MessageBox.Show(5)
 
    
Catch ex As Exception
    'Err_Msg:
    MessageBox.Show("关键字重复或空值,不能保存!")
    'Exit Sub
End Try

还有狐爸在原贴里的那段代码也测试过了,问题跟测试1和测试2的一样,只要是Datatable 出错 Try Catch就形同虚设,没有继续在原贴上写而开新贴的原因是,怕没有引起狐爸的重视!怕贴子沉得太快,没人关注。


 回到顶部
总数 11 1 2 下一页