Re: Continued try blocks

From: Date: Mon, 29 Apr 2013 15:43:55 +0000
Subject: Re: Continued try blocks
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message

So, in this example, if, say, bar() throws a SomeException , the code would then resume and execute baz() after the catch block. Just presenting the idea here, no RFC actually , I'm collecting thoughts and notices.
It seems like you want application specific flow control (caller specific) when particular exceptions are raised. This is achievable through goto, why not use that? http://3v4l.org/HsdlD <?php class SomeException extends Exception {} function foo() {
    echo 'attempting 1' . PHP_EOL;
} function bar($someCondition) {
    echo 'attempting 2 with ' . $someCondition . PHP_EOL;
    if ($someCondition == null) {
        throw new SomeException('Foo foo fooey');
    }
} function baz() {
    echo 'attempting 3' . PHP_EOL;
    throw new Exception('Boo boo bar');
} function fixupforbar(&$someCondition) {
    $someCondition = 5;
} /** main() **/ $someCondition = null; try {
    foo();
    BAR: bar($someCondition);
    baz();
} catch (SomeException $e) {
    fixupforbar($someCondition);
    goto BAR;
} catch (Exception $e) {
    echo 'Exception caught: ' . $e->getMessage() . PHP_EOL;
} finally {
    echo 'Cleaning up' . PHP_EOL;
} -ralph

Thread (33 messages)

« previous php.internals (#67193) next »