问题描述
我具有此功能,可以处理与ssh的连接。
connectSession()
{
std::string _ErrMsg;
MyException errMsg;
int port = 22;
try
{
if (my_ssh_session == NULL) {
std::cout << "Error creating ssh session" << std::endl;
throw MyException("Error in creating session");
}
try
{
ssh_options_set(my_ssh_session,SSH_OPTIONS_HOST,(const void*)(authentication.ip));
ssh_options_set(my_ssh_session,SSH_OPTIONS_USER,(const void*)(authentication.userName));
ssh_options_set(my_ssh_session,SSH_OPTIONS_PORT,&port);
int rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK) {
std::cout << "Error with connecting" << std::endl;
_ErrMsg = ssh_get_error(my_ssh_session);
ssh_free(my_ssh_session);
throw MyException(_ErrMsg);
}
rc = ssh_userauth_password(my_ssh_session,NULL,(const char*)(authentication.pw));
if (rc != SSH_AUTH_SUCCESS) {
std::cout << "Authentication failed " << ssh_get_error(my_ssh_session) << std::endl;
_ErrMsg = ssh_get_error(my_ssh_session);
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
throw invalid_argument(_ErrMsg);
}
}
catch (const invalid_argument& e)
{
throw_with_nested(invalid_argument(e.what()));
}
}
我已将my_ssh_session = ssh_new();
放入构造函数中。
我希望能够在ssh_options_set
发生异常时捕获异常(例如,当评论my_ssh_session = ssh_new();
时抛出异常)错误。)我该怎么办?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)