如何在VB.NET中使用try catch而不过度广泛捕获 [英] How to use try catch in VB.NET without overly broad catch
问题描述
我项目的安全审核结果显示错误
尝试
//代码
catch
/ / rollback
// msg
结束尝试
// - 报告显示结束时出错尝试
错误消息是
page.aspx.vb第364行的catch块处理大量的
异常,可能会陷入不同的情况此计划中不应处理的问题或问题。
//帮助//
我尝试了什么:
我尝试删除END TRY,但显示错误
试试
Catch
结束尝试
是完整的声明。
Security audit result of my project showing error on
try
// code
catch
//rollback
//msg
end try
//--Report Shows an error on "End Try"
Error Message Is
The catch block at page.aspx.vb line 364 handles a broad swath of
exceptions, potentially trapping dissimilar issues or problems that should not be dealt with at this point in the program.
//Help Please//
What I have tried:
Im Try to remove "END TRY" but it shows error
Try
Catch
End try
is complete statement.
推荐答案
当你自己使用Catch时,它会捕获抛出的每个异常(并丢弃同时发生的所有信息)。
When you use Catch on it's own, it catches every exception that is thrown (and discards all the information on what happened at the same time).
Dim Top As Double = 5
Dim Bottom As Double = 0
Dim Result As Integer = 0
Try
Result = Top / Bottom
Catch ex As System.OverflowException
MessageBox("Attempt to divide by zero:" + ex.Message)
End Try
将Catch限制为可以执行某些操作的例外。
Restricts the Catch to just the exceptions you can do something about.
这篇关于如何在VB.NET中使用try catch而不过度广泛捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!