我如何看待在快速运动场上的例外?

时间:2022-05-03 11:45:36

I was playing around with Swift, and have this code in a playground

我在和斯威夫特玩,在操场上有这个密码

class Foo {
    let value: String
    init(value: String!)
    {
        self.value = value
    }
}

let x : String? = nil
let foo = Foo(value: x)

The bottom line should throw an exception in the initializer, because I am unwrapping x which is nil. However I am not able to see the exception message or the fact that an error happens at runtime. If I add code below this, it does not get run (no output gets shown).

底线应该在初始化器中抛出一个异常,因为我正在解包为nil的x。但是,我无法看到异常消息或在运行时发生错误的事实。如果我在下面添加代码,它不会运行(不会显示输出)。

How can I see the exceptions that are thrown at runtime in a Swift playground ?

我怎么能看到在运行时在快速运动场上抛出的异常呢?

2 个解决方案

#1


6  

Click the Assistant Editor icon to open the Console Output panel.

单击辅助编辑器图标以打开控制台输出面板。

The error is listed there.

这里列出了错误。

#2


3  

As of Xcode 6.0 Beta 5, exceptions will now show up with an error marker in the source editor and in the result sidebar. If you press the quicklook button in the result sidebar we will show you the full backtrace of the exception.

从Xcode 6.0 Beta 5开始,异常将在源代码编辑器和result侧栏中显示一个错误标记。如果您在result侧栏中按下quicklook按钮,我们将向您显示异常的完整回溯。

#1


6  

Click the Assistant Editor icon to open the Console Output panel.

单击辅助编辑器图标以打开控制台输出面板。

The error is listed there.

这里列出了错误。

#2


3  

As of Xcode 6.0 Beta 5, exceptions will now show up with an error marker in the source editor and in the result sidebar. If you press the quicklook button in the result sidebar we will show you the full backtrace of the exception.

从Xcode 6.0 Beta 5开始,异常将在源代码编辑器和result侧栏中显示一个错误标记。如果您在result侧栏中按下quicklook按钮,我们将向您显示异常的完整回溯。