我有一段这样的代码。
class Facebook
{
WebBrowser wb = new WebBrowser();
public bool isDone = false;
public Facebook()
{
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}
public void Navidate(string URL = "http://www.facebook.com")
{
wb.Navigate(URL);
}
public void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = sender as WebBrowser;
if (wb != null && wb.StatusText.Contains("404"))
{
// i want to throw this exception to outside how ?
throw new ServerNotFound("Error 404");
}
else
{
isDone = true;
}
}
}
public class ServerNotFound : Exception
{
public ServerNotFound(string Message)
: base(Message)
{
}
在这里您可以看到 Web 浏览器事件它可以引发异常我想像这样处理这个异常。
static class Program
{
[STAThread]
static void Main()
{
try
{
Facebook fb = new Facebook();
fb.Navidate();
do
{
Application.DoEvents();
}
while (!fb.isDone);
}
catch (ServerNotFound ex)
{
// i want to handle that exception here ?
MessageBox.Show(ex.Message);
}
}
}
你能帮帮我吗?由于事件,它不起作用。