尝试使用My.Computer.Network.DownloadFile从VB 2013 Express中的FTP服务器获取文件。当文件在那里的时候,一切都很好。但是,当找不到文件时,我无法捕获结果。使用尝试-捕捉,但它从来没有击中捕获。它会引发一个“应用程序中发生了未处理的异常.”错误。
任何帮助都将不胜感激!
Try
My.Computer.Network.DownloadFile(server_name, file_name, user_name, password, False, 500, True)
Catch ex As ArgumentException
MsgBox(ex.GetType().ToString())
Catch ex As TimeoutException
MsgBox(ex.GetType().ToString()) 'Label1.Text = ex
End Try发布于 2014-07-17 17:21:25
看看文献资料 --您没有捕获几乎所有DownloadFile可能抛出的异常类型。
The following conditions may cause an exception to be thrown:
The drive name is not valid (ArgumentException).
destinationFileName ends with a trailing slash (ArgumentException).
overwrite is set to False and the destination file already exists (IOException).
The server does not respond within the specified connectionTimeout (TimeoutException).
The authentication fails (SecurityException).
User lacks necessary permissions (SecurityException).
The request is denied by the website (WebException).试着
Try
My.Computer.Network.DownloadFile(server_name, file_name, user_name, password, False, 500, True)
Catch ex As Exception
MsgBox(ex.GetType().ToString())看看是怎么回事。
https://stackoverflow.com/questions/24809578
复制相似问题