本文介绍了调试时禁用Visual Basic Err对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VB.NET编写的Windows服务,并在运行时记录错误,它使用对象的Visual Basic。当我正在调试服务时,它不会给我任何错误,但同时它设置 Err 对象与号码 13 这意味着我的类型不匹配(根据)任何想法如何在调试时强制抛出运行时异常?我试过评论下面的代码,但没有运气: -

  On Error Resume Next 


解决方案

您可以使用Err.Raise()方法或Throw Err.GetException()方法,如果Err有任何错误。

 如果Err.Number<> 0然后
抛出Err.GetException()
结束如果



 如果Err.Number<> 0然后
Err.Raise(Number:= Err.Number,Source:= Err.Source,描述:= Err.Description,HelpFile:= Err.HelpFile,HelpContext:= Err.HelpContext)
结束如果


I have a windows service written in VB.NET and for error logging at runtime it uses the Err object of Visual Basic. When I am debugging the service it is not giving me any error but at the same time it is setting the Err object with number 13 which means I have a type mismatch somewhere (According to Error List) Any idea how I can forcefully throw the runtime exception while debugging? I have tried commenting the below code but no luck:-

On Error Resume Next
解决方案

You can use Err.Raise() method or Throw Err.GetException() method if Err has any error.

If Err.Number <> 0 Then
    Throw Err.GetException()
End If

OR

If Err.Number <> 0 Then
    Err.Raise(Number:=Err.Number, Source:=Err.Source, Description:=Err.Description, HelpFile:=Err.HelpFile, HelpContext:=Err.HelpContext)
End If

这篇关于调试时禁用Visual Basic Err对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:42