class point {int x,y,z} to hardErr() /* Access undefined object to cause a hard error. */ { array of string s; s[0] = 'H'; } to punt1() { punt("I'm not doing this for fun, but here goes.", "crashOut", 1); } to punt0() { punt("I can't help it, I'm a failure."); } array of var of to () punters = (punt1, punt0, hardErr); to doSomethingFlaky(string when, var of to() punter) { for (i in 0 til 3) print("Testing " + i); print("oh rats..."); punter(); } to flakarelli(int level) { int i = 0; print("welcome to flakarelli level " + level); for (v in punters) { try { doSomethingFlaky("flaky test " + level, v); } catch (seriousError e) { print("Caught punter " + i + ". I'm at level " + level); e.report(); } i += 1; } } flakarelli(-1); class myErr extends error { int mySecretCode = 870; to init(string message) { parent.init(message); } } to bail() { myErr e = ("Owwweee!"); throw(e); } to bailHarder() { punt("Ock, I'm out of here"); } to risk() { try { string inner = "innerString"; bail(); } catch (myErr e) { e.report(); } } to riskMore() { try { try { bailHarder(); } catch (myErr e) { print("Caught inner"); e.report(); } } catch (error e) { print("Caught outer"); e.report(); } } to chainedPunt() { try { try { bail(); } catch (error e) { puntMore(e, "inner error in chainedPunt"); } } catch (error e) { print("Caught chained"); e.report(); } } to chainedThrow() { try { try { bail(); } catch (error e) { error moreErr = ("No, really, I can handle it", "overconfident"); throwMore(e, moreErr); } } catch (error e) { e.report(); print("Caught chained"); } } risk(); riskMore(); chainedPunt(); chainedThrow(); try { punt("Bail out of non-function"); } catch (error e) { e.report(); } try { print("Bravely running away."); punt("I just got scared"); } catch (error e) { print("problem: " + e.asString()); }