【发布时间】:2011-06-20 09:17:45
【问题描述】:
例如,我想知道异常是否是“内存溢出异常”。但是,如果操作系统上的语言不是英语而是中文或德语,则消息会发生变化。而且我再也看不到消息字符串了。在MSDN 上,我没有找到可以使用的异常编号。如何找到异常号?
Public Shared Sub Main()
Dim x As Integer = 0
Try
Dim y As Integer = 100 / x
Catch e As Exception'here, 123 is not working
if e is ArithmeticException(123) then Console.WriteLine("Generic Exception Handler: {0}", e.ToString())
End Try
End Sub
示例(查看
Try
m_DxFilGraphManager.Run()
Catch ex As System.Runtime.InteropServices.COMException
If ex.Message.Contains("0x800705AA") Then '<-- Bad methode. How to do it better?
Return "#ERROR: Can not start capturing. It seems to be a possiblity to change the IEEE 1394 bus host controler system driver in your device manager to 'legacy / alt'. " & ex.Message
Else
Return "#ERROR: " & ex.Message
End If
End Try
【问题讨论】:
-
ErrorCode不是System.Exception的普通成员。一些特定的异常类型提供了这样的成员(还可以考虑System.Data.SqlClient.SqlException上的各种信息),但通常您首先按类型捕获,然后(如果需要)使用异常(类型)特定信息查看是否有更多可用信息。跨度>
标签: .net exception error-handling