Allow Python-like error handling with a non-catching continuation block
Submitted by car..@..oo.com
Link to original bug (#650227)
Description
Python has a useful syntax for try/catch that should be in Vala too. It allows a separate "else" block that is essentially a continuation of the "try" block but exceptions are no longer caught. The problem with current Java-like flow is that you are compelled to put code in the "try" block for which you really don't intend to handle errors, because the local scope is lost if the continuing code is placed after the try/catch clauses. Suggested syntax for Vala, reusing the existing "then" keyword:
try { // Do something that might throw an error. } then { // This block will only run if no errors were thrown out of the previous block. // The scope of the previous block is retained here, but exceptions thrown out of here can not be caught by any following "catch" block, instead it will be propagated. } catch () { // This will catch errors from the "try" block, but not from the "then" block. } finally { // This block will be evaulated as usual, only requirement is that the "try" block has once been entered. }
Version: 0.12.x