Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the "else" clause is a bit limiting, unless you don't care about any exceptions thrown there (or you want to bubble those exceptions)... From my understanding of Python, it's basically the equivalent of this:</p> <pre><code>try { //...Do Some Stuff Here try { // Else block code here } catch (Exception $e) { $e-&gt;elseBlock = true; throw $e; } } catch (Exception $e) { if (isset($e-&gt;elseBlock) &amp;&amp; $e-&gt;elseBlock) { throw $e; } // catch block code here } </code></pre> <p>So it's a bit more verbose (since you need to re-throw the exceptions), but it also bubbles up the stack the same as the else clause...</p> <p><strong>Edit</strong> Or, a bit cleaner version (5.3 only)</p> <pre><code>class ElseException extends Exception(); try { //...Do Some Stuff Here try { // Else block code here } catch (Exception $e) { throw new ElseException('Else Clasuse Exception', 0, $e); } } catch (ElseException $e) { throw $e-&gt;getPrevious(); } catch (Exception $e) { // catch block code here } </code></pre> <p><strong>Edit 2</strong></p> <p>Re-reading your question, I think you may be overcomplicating things with an "else" block... If you're just printing (which isn't likely to throw an exception), you don't really need an else block:</p> <pre><code>try { // Do Some stuff print "Success"; } catch (Exception $e) { //Handle error here print "Error"; } </code></pre> <p>That code will only ever print <em>either</em> <code>Success</code> or <code>Error</code>... Never both (since if the <code>print</code> function throws the exception, it won't be actually printed... But I don't think the <code>print</code> CAN throw exceptions...).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload