Cap'n Proto 在抛出 'kj::ExceptionImpl' 的实例后终止调用

Cap'n Proto terminate called after throwing an instance of 'kj::ExceptionImpl'

调用 Cap'n Proto 的 writeMessageToFd(pipe, message); 时出现此错误:

terminate called after throwing an instance of 'kj::ExceptionImpl'
  what():  src/kj/io.c++:323: failed: ::writev(fd, current, iov.end() - current): Bad file descriptor; fd = -1
stack: 0x7efead69cf89 0x7efead6a0c7f 0x7efead6a2648 0x7efead6a24f7 0x7efead8f40b7 0x7efead8f42a4 0x402c7b 0x402a36 0x4028df 0x7efeabd50e50 0x7efeabd5181a 0x7efeabd52669 0x7efeabd52a03 0x7efeabd52bb2 0x402865 0x4027ab

你并没有真正问过问题,但我可以从那个异常中告诉你你不应该尝试用无效的文件描述符调用 writeMessageToFd(异常文本告诉你这个 "Bad file descriptor; fd = -1") .

您有两个选择: - 如果 pipe == -1 不要调用该函数(可能最好,你真的应该检查 returned pipe 的调用没有 return -1) - 用 try/catch 包围对 writeMessageToFd() 的调用并适当地处理异常

你真的应该选择前者并适当地处理管道中的 -1 值。