将Swift错误处理模型与C++连接起来
Bridging Swift Error Handling Model to C++
摘要:
错误处理是对程序中的错误条件做出响应并从错误条件中恢复的过程。在Swift中,错误由符合Error协议的类型的值表示。抛出一个错误可以让您指示发生了一些意外的事情,并且正常的执行流无法继续。throw语句用于抛出错误。可选返回值用于表示值的缺失,但当操作失败时,了解导致失败的原因通常很有用,这样代码就可以相应地做出响应。因此,我建议将Swift错误处理建模与C++连接起来,以提高程序设计语言之间的互操作性。其主要思想是能够抛出一个C++异常,该异常存储一个必须由C++类表示的Swift Error。除此之外,为了支持不使用异常的C++程序,我提出了一个额外的互操作性模式来抛出函数。当C++异常被禁用时,C++函数应该返回一个结果值,其中包含函数返回的值或Swift Error值:Swift::Exception<T>类。
英文摘要:
Error handling is the process of responding to and recovering from error conditions in the program. In Swift, errors are represented by values of types that conform to the Error protocol. Throwing an error lets you indicate that something unexpected happened, and the normal flow of execution can't continue. A throw statement is used to throw an error. Optional returns are used to represent the absence of a value, but when an operation fails, it's often useful to understand what caused the failure so that code can respond accordingly. Therefore, I propose to bridge the Swift Error Handling modeling to C++ to improve the interoperability between the programming languages. The main idea is to be able to throw a C++ exception that stores a thrown Swift Error that has to be represented by a C++ class. In addition to that, to support C++ programs that don't use exceptions, I propose an additional interoperability mode for throwing functions. When C++ exceptions are disabled, C++ functions should return a result value that contains either the value returned by the function or the Swift Error value: the Swift::Exception<T> class.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。