Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Wednesday, March 18, 2015

C# try...catch scope

If you do this
XDocument xdocument;
try {
  xdocument = XDocument.Load(args[1]);
} catch (Exception e) {
  MessageBox.Show("All kinds of fucked up shit happened - " + e.ToString());
  Environment.Exit(-3);
}
xdocument.DoStuff();
you'll get a 'use of unassigned variable' error for the xdocument.DoStuff() line.

What C# actually means is that xdocument might be unassigned at that point in the code, cos we didn't assign it on the first line of the example.

Solution is to replace the first line with:

XDocument xdocument = null;

As this page told me.

Followers

Blog Archive