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.
翻译:错误处理是响应和从程序错误条件中恢复的过程。 在 Swift 中, 错误处理由符合错误协议的类型的值来表示。 丢出错误会让您显示意外发生, 正常执行过程无法继续 。 丢出语句用于丢出错误 。 选择返回用于代表没有值, 但当操作失败时, 理解导致失败的原因往往有用, 以便代码能够相应响应 。 因此, 我提议将 Swift 错误处理模型连接到 C++, 以改善程序语言之间的互操作性。 主要的想法是能够丢出一个 C++ 例外, 即存储一个必须由 C++ 类代表的被扔出 Swift 错误。 此外, 为了支持不使用例外的 C++ 程序, 我提议一个额外的互操作模式来丢弃函数。 当 C+++ 例外被禁用时, C++ 函数应该返回包含函数返回的值或 Swift 错误值的结果值: Swift < T> 类 。