try finally code example
Example 1: try catch haxe
import haxe.Exception;
class Main {
static function main() {
try {
try {
doSomething();
} catch(e:Exception) {
trace(e.stack);
throw e; //rethrow
}
} catch(e:Exception) {
trace(e.stack);
}
}
static function doSomething() {
throw new Exception('Terrible error');
}
}
Example 2: try-catch-finally
localStorage.getItem(key)
try {
data = JSON.parse(key)
}
catch (e) {
// if the code errors, this bit of code will run
}
finally {
return data
}