Stack unwinding is just the process of navigating up the stack looking for the handler. Wikipedia summarizes it as follows:

Some languages call for unwinding the stack as this search progresses. That is, if function f, containing a handler H for exception E, calls function g, which in turn calls function h, and an exception E occurs in h, then functions h and g may be terminated, and H in f will handle E.

Whereas a Swift error doesn't unwind the stack looking for a handler. It just returns, and expects the caller to handle the thrown error. In fact, the sentence after the one you quote goes on to say:

As such, the performance characteristics of a throw statement are comparable to those of a return statement.

So, using that first example, where f called g which calls h, in Swift, if you want f to catch the error thrown by h, then:

  • h must explicitly be marked that it throws errors;
  • g must explicitly try its call to h;
  • g must also be marked that it throws errors, too; and
  • f must explicitly try its call to g.

In short, while some other languages offer stack unwinding in the process of finding the exception handler, in Swift error handling, you must either explicitly catch the error thrown by functions you try, or be designated as a function that throws so that failed try calls will be thrown back up to the caller. There is no automatic unwinding of the stack in Swift.

All of this is unrelated to the question of whether deallocation takes place. As you've seen, yes, the throw in Swift behaves much like return, deallocating those local variables.

It's worth noting that not all exception handling that involves stack unwinding does the deallocation. Generally it does (because of course we want it to clean up when we're handling exceptions), but for example, "the GNU C++ unwinder does not call object destructors when an unhandled exception occurs. The reason for this is to improve debuggability." (From Exception Handling in LLVM.) Clearly, that's only appropriate for unhandled exceptions in debugging environments, but it illustrates the issue that unwinding the stack doesn't necessarily mean that objects are deallocated.

https://stackoverflow.com/questions/46814233/error-handling-in-swift-does-not-involve-stack-unwinding-what-does-it-mean

Error handling in Swift does not involve stack unwinding. What does it mean?的更多相关文章

  1. Erlang error handling

    Erlang error handling Contents Preface try-catch Process link Erlang-way error handling OTP supervis ...

  2. setjmp()、longjmp() Linux Exception Handling/Error Handling、no-local goto

    目录 . 应用场景 . Use Case Code Analysis . 和setjmp.longjmp有关的glibc and eglibc 2.5, 2.7, 2.13 - Buffer Over ...

  3. Error Handling

    Use Exceptions Rather Than Return Codes Back in the distant past there were many languages that didn ...

  4. 19 Error handling and Go go语言错误处理

    Error handling and Go go语言错误处理 12 July 2011 Introduction If you have written any Go code you have pr ...

  5. Error Handling Functions(微软对于出错的情况下提供的所有函数,比如SetThreadErrorMode,SetErrorMode,SetLastErrorEx,FatalAppExit,CaptureStackbackTrace)

    The following functions are used with error handling. Function Description Beep Generates simple ton ...

  6. ASP.NET Error Handling

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...

  7. Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(十二)之Error Handling with Exceptions

    The ideal time to catch an error is at compile time, before you even try to run the program. However ...

  8. MySQL Error Handling in Stored Procedures 2

    Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...

  9. Error Handling and Exception

    The default error handling in PHP is very simple.An error message with filename, line number and a m ...

随机推荐

  1. OpenCV使用CMake和MinGW的编译安装

    官方教程:https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows 软件环境: Qt:5.11 CMake-3.14.4 OpenCV-4.1. ...

  2. TPad需求和迭代

    需求和迭代最主要的区别是什么

  3. influx db

    1.查看数据库中的tag keys:     如果需要查看field的直接改 > show tag keys on test; name: garage_pc_overviewtagKey--- ...

  4. vs2019发布Web到云服务器(IIS)

    捣鼓了也有几天,到处收集资料终于折腾出来,做点小笔记 原文地址:https://www.cnblogs.com/potential/p/3751426.html 一.我的环境: Windows Ser ...

  5. 【题解】Editor [HDU4699]

    [题解]Editor [HDU4699] 传送: \(Editor\) \([HDU4699]\) [题目描述] 有一个维护整数序列的强大编辑器,初始状态为空,下面提供五种不同的操作,给出的总操作次数 ...

  6. 补习系列(17)-springboot mongodb 内嵌数据库【华为云技术分享】

    目录 简介 一.使用 flapdoodle.embed.mongo A. 引入依赖 B. 准备测试类 C. 完善配置 D. 启动测试 细节 二.使用Fongo A. 引入框架 B. 准备测试类 C.业 ...

  7. ajax 执行成功以后返回的数据走的是error方法而不是success方法的问题

    今天在一个功能的时候发现写的ajax的方法执行后台代码成功后返回前台时执行的是error方法而不是success方法,代码如下 jQuery('#form').ajaxSubmit({ type: & ...

  8. Typora使用手册

    块状元素: 标题: # 标题1 ## 标题2 ### 标题3 #### 标题4 ##### 标题5 ###### 标题6 使用快捷键: Ctrl + 1-6 块引用 使用符号 > 就可以进入引用 ...

  9. 详解js中的this指向

    this指向问题是个老生常谈的问题了,现在我给大家一个例子 var obj={ bar:'Cynthia' , foo:function(){ console.log(this.bar,"w ...

  10. Middle English finaunce金融

    Etymology finance From Middle English finaunce, a surety bond.A supply of money or goods. With thy b ...