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


------------------越是喧嚣的世界,越需要宁静的思考------------------ 合抱之木,生于毫末;九层之台,起于垒土;千里之行,始于足下。 积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉。故不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓无爪牙之利,筋骨之强,上食埃土,下饮黄泉,用心一也。蟹六跪而二螯,非蛇鳝之穴无可寄托者,用心躁也。