Could any one explain, why am I not getting exception from blow code:
Action <Exception> myact = ( ) => {
throw new Exception( "test" );
};
Task myactTask = Task.Factory.StartNew( ( ) => myact);
try {
myactTask.Wait( );
Console.WriteLine( myactTask.Id.ToString( ) );
Console.WriteLine( myactTask.IsCompleted.ToString( ) );
}
catch( AggregateException ex ) {
throw ex;
}
on the other hand if replace Action “myact” with method “myact()” then I can get exception and it can be handeled with try catch block.
public static void myact( ) {
throw new Exception( "test" );
}
This does not execute your action, it is a function that returns a reference to your Action.
This will execute it and throw/catch the exception.