Задайте вопросЗадайте вопрос
 

ОтвеченоDon't get an AggregateException ...

  • 22 июня 2009 г. 19:37ManfredSteyer Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     С кодом
    Hi,

    I just wanted to try out the usage of AggregateExceptions. So I tried to provoke such an exception - without success.
    You can find my code at the end of this posting. What have I done wrong ?

    Regards,
    Manfred

       class TransporterDamagedException : ApplicationException {}
        class CannotLocatePersonException : ApplicationException { }
    
        class Starship
        {
            public void BeamUp(String person, bool urgent)
            {
                if (urgent) throw new TransporterDamagedException();
                if (person == null) throw new CannotLocatePersonException();
                Console.WriteLine("Beam up " + person + "..." );
            }
        }
    
        public class ExceptionSample
        {
            public void Demo()
            {
                Starship ship = new Starship();
    
                try
                {
                    Task t1 = Task.Factory.StartNew(() => ship.BeamUp("Kirk", true));
                    Task t2 = Task.Factory.StartNew(() => ship.BeamUp(null, false));
                    Task t3 = Task.Factory.StartNew(() => ship.BeamUp("Spock", true));
    
                    t1.Wait();
                }
                catch (AggregateException ae)
                {
                    ae.Handle((e) =>
                    {
                        Console.WriteLine(" > " + e.GetType().Name);
                        return true;
                    });
                }
            }
        }
    

Ответы

Все ответы