我正在使用sshNet开发一个通过SSH连接到Linux服务器的小程序。
它运行正常,但是当用户或传递错误时,它会抛出一个默认的异常消息,我想捕获异常并显示一个带有特定文本的MessageBox。
代码:
public void comandoSSH(string comando)
{
using (var ssh = new SshClient(ip, user, pass))
{
try
{
ssh.Connect();
var responseSsh = ssh.RunCommand(comando);
var response = responseSsh.Result;
ssh.Disconnect();
Output(response);
}
catch (Exception ex)
{
MessageBox.Show(
"My Text",
"Warning!",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
但它不起作用,它只显示默认消息。
有什么想法吗?谢谢!