我正在使用try..catch進行錯誤處理。我得到的消息顯示爲錯誤處理消息類型
messagebox.show (ex.tostring)
但它提供了很長的消息。
有可能只是得到實際的錯誤,或者我可以給我自己修改的消息,基於什麼ex包含?
謝謝
我正在使用try..catch進行錯誤處理。我得到的消息顯示爲錯誤處理消息類型
messagebox.show (ex.tostring)
但它提供了很長的消息。
有可能只是得到實際的錯誤,或者我可以給我自己修改的消息,基於什麼ex包含?
謝謝
使用Exception.Message財產。
MessageBox.Show(ex.Message)
您可以打印Message
屬性的內容。通常這是一個簡短的描述性信息,沒有堆棧的全部技術細節。
Exception.Message
包含異常的簡單描述(例如「對象引用未設置...」)。
Exception.ToString()
包含對異常的描述以及完整的堆棧跟蹤。
Message
property僅返回消息(這解釋了例外的原因)。
Dim message As String = "Message: " & ex.Message
MessageBox.Show(message)
不過,如果你只希望name of the Exception's Type:
Dim typeName = ex.GetType().Name
如果你想在消息更少文本,然後嘗試改變
Exception.ToString to Exception.Message
爲的Massimiliano Peluso的說,如果你想然後定製,我希望這會給你一些想法。
Try
'Your Codes...
Catch oledbEx As OleDbException
MessageBox.Show("Your message")
Catch ex As Exception
MessageBox.Show("Your message")
Catch ioEX As IOException
MessageBox.Show("Your message")
Catch dataEX As DataException
MessageBox.Show("Your message")
End Try