// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace GoTo { public static class Luck { private static Random rng = new Random(); public static bool InLuck() { return rng.NextDouble() > 0.2; } } public class X { private string id; private X(string id) { this.id = id; Console.WriteLine("X {0} created", id); } public static X Create(string id) { if(Luck.InLuck()) { return new X(id); } else { return null; } } public void Close() { Console.WriteLine("X {0} closed", id); } } public class Program { public static void Main(string[] args) { X o1 = X.Create("A"); if(o1 == null) { Console.WriteLine("Error creating A"); goto lbl_done; } X o2 = X.Create("B"); if(o2 == null) { Console.WriteLine("Error creating B"); goto lbl_close1; } // 20 lines Console.WriteLine("Part 1"); if(!Luck.InLuck()) { Console.WriteLine("Error during execution"); goto lbl_close2; } // 20 lines Console.WriteLine("Part 2"); lbl_close2: o2.Close(); lbl_close1: o1.Close(); lbl_done: // done } } }