Exemple #1
0
 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();
         }
     }
 }
Exemple #2
0
    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");
            }
        }
    }