static void Main(String[] args) { try { int x = new ParserA().GetData(); int y = new ParserB().GetData(); } catch (InvalidDataException ex) { Parser parser = ex.Data["owner"] as Parser; if (parser != null) { parser.handleError(); } } }
static void Main(String[] args) { try { int x = new ParserA().GetData(); int y = new ParserB().GetData(); } catch (InvalidDataException ex) { Parser parser = ex.Data["owner"] as Parser; if (parser != null) { parser.handleError(); } // or even this if you prefer: if (parser is ParserA) { Console.WriteLine("A"); } } }