如何在服务器中引发异常并在客户端 c++ 中捕获它
How to throw an exception in server and catch it in client c++?
我想知道我是否可以从服务器发送异常并在客户端中接收它。这是我的服务器:
void MyServer::on_new_message(int identifier, string message) {
if(/*some condition for message*/)
throw BadIO();
}
这是我客户的主要内容:
int main(){
try{
cin>>c;
socket.send(c);
socket.receive();
}
catch(BadIO& exp)
{
cout<<exp.what()<<endl;
}
return 0;
}
运行此代码后,我得到:
在抛出"BadIO"实例后终止调用 已中止(核心已转储)
提前致谢:)
这是可能的。
异常需要在服务器中序列化,就像在进程之间传递的任何其他对象一样。具有针对异常的特殊消息,以便socket.receive
可以检测到它,反序列化异常并将其抛出到客户端中。
相关文章:
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 如何将函数集合传递给客户端类,以便将它们当作客户端类本身的成员使用
- 使用调试/崩溃报告将应用程序部署到客户端
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 从服务器传输到客户端的消息不会出现
- OpenSSL TLS服务器-使用客户端证书白名单
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 提升 Asio TCP 服务器 处理多个客户端
- boost::asio UDP 广播客户端仅接收"fast"数据包
- 如何绑定 C++ gRPC 客户端的网络接口
- C++套接字客户端到 Python 服务器未创建连接
- 用于解析 win64 堆栈跟踪的命令行客户端(可以访问符号服务器)
- 将相机数据从服务器实时流式传输到客户端
- 如何将 Firebase 与基于 Linux 的客户端应用配合使用,以便与服务器进行双向消息通信
- GRPC C++ TLS 客户端 grpc::SslCredentials() 方法不返回
- 计算出有多少客户端可以连接到我正在使用的一些tcp服务器代码
- 如何暂停插孔音频客户端
- 不将数据 socket.io c++(客户端)发送到 nodejs(服务器)socket.io