什么内置的异常用于要求调用方法?

时间:2019-01-22 16:49:35

标签: php exception

假设您要先调用某个方法再调用另一个方法。是否有适当的内置例外?例如,

var engine = AVAudioEngine()
var mixer = AVAudioMixerNode()
var playerNodes = [AVAudioPlayerNode]()

func prepare() {
    engine.attach(mixer)
    engine.connect(mixer, to: engine.outputNode, format: nil)

    // Create playernode and add to playerNodes

    for node in playerNodes {
        engine.attach(node)
        engine.connect(node, to: mixer, format: nil)
    }

    try! engine.start()
}

func play() {
    for node in playerNodes {
        // schedule file/segment/buffer
        node.play(at: startTimeForNode)
    }
}

在此示例中,什么样的内置异常是对通用lastRenderTime的适当替代?

1 个答案:

答案 0 :(得分:0)

这是php7的官方异常层次结构

http://php.net/manual/en/spl.exceptions.php


引起我注意的异常是

var value string = x2["hello"]

  • 表示程序逻辑错误的异常。这种 异常应直接导致代码中的修复。

LogicException

  • 如果回调引用的是未定义的方法,或者如果 缺少一些争论。

BadMethodCallException似乎不太合适,而BadMethodCallException听起来是所有内置异常中最好的。