linux-packaging-mono/mcs/tests/test-ex-filter-04.cs
Jo Shields 3c1f479b9d Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
2015-04-07 09:35:12 +01:00

74 lines
1.1 KiB
C#

using System;
using System.Threading.Tasks;
class X
{
static Exception ex = new ApplicationException ();
public static int Main ()
{
if (Test (5, null).Result != 5)
return 1;
try {
Test (5, ex).Wait ();
return 2;
} catch (AggregateException ae) {
if (ae.InnerException != ex)
return 3;
}
try {
Test (15, ex).Wait ();
return 4;
} catch (AggregateException ae) {
if (ae.InnerException != ex)
return 5;
}
try {
TestGeneric (5).Wait ();
return 10;
} catch (AggregateException ae) {
if (ae.InnerException != ex)
return 11;
}
try {
TestGeneric (15).Wait ();
return 12;
} catch (AggregateException ae) {
if (ae.InnerException != ex)
return 13;
}
return 0;
}
async static Task<int> Test (int x, Exception e)
{
try {
Console.WriteLine (x);
if (e != null)
throw e;
} catch (Exception) when (x != 15) {
await Task.FromResult (0);
throw;
}
return x;
}
async static Task<int> TestGeneric (int x)
{
try {
Console.WriteLine (x);
throw ex;
} catch when (x != 15) {
await Task.FromResult (0);
throw;
}
return x;
}
}