如何捕获异常并显示其详细信息

如何捕获异常并显示其详细信息

本文介绍了如何捕获异常并显示其详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何捕获错误,然后在自定义 ListBox 之类的东西中显示其详细信息。这样做的目的是允许显示简单的自定义消息,例如糟糕,出了点问题!但仍能够提供故障排除信息。如果有人可以帮助我构建此代码,我将不胜感激。

I'm wondering how I'd go about catching an error and then displaying its details in a custom ListBox or something. The idea is to allow a custom message to appear that's simple, like "Woops, something's went wrong!" but still be able to provide the information for troubleshooting. If someone could help me build this code I'd be really grateful.

所以说我有可能导致错误的代码,例如连接到互联网。如何捕捉错误并以单独的形式显示它(弹出窗口)?

So say I have code that could result in an error, like connecting to the internet. How would I be able to catch the error and display it in a separate form (pop-up window)?

如果这个接缝确实很基础,我深表歉意,但是我对此并不陌生,只是不喜欢正常的错误窗口。

I apologize if this seams really basic but I'm new to this stuff and I just don't like the normal error window.

推荐答案

最后,我得出以下结论:

In the end I ended up with this:

Try
    'Code which may error
Catch ex As Exception
    MessageBox.Show("Whoops! An error was encountered during the login-in stage. The Server may be offline, un-reachable or your Server Credentials may be in-correct. Please contact U.G Studio for further details. " & _
    vbNewLine & "" & vbNewLine & String.Format("Error: {0}", ex.Message))

它允许我显示自定义消息,同时仍保留有关错误的技术信息。

It allows me to display a custom message whilst still retaining the 'technical' information about the error.

感谢帮助的人!

这篇关于如何捕获异常并显示其详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:30