c# - Why is this exception not caught? -


i'm trying run following code:

class program {     static void main(string[] args)     {         var task = task.factory.startnew(() =>             {                 throw new applicationexception("message");             });         try         {             task.continuewith(t => console.writeline("end"));         }         catch (aggregateexception aex)         {             console.write(aex.innerexception.message);         }     } } 

i expected exception caught in following location:

        catch (aggregateexception aex)         {             console.write(aex.innerexception.message);         } 

but not happening. why so?

you're printing out task - won't have completed yet.

printing out task doesn't wait complete, or try fetch value.

if change code to:

try {     task.wait(); } 

... then i'd expect catch exception.

(i using task<t>.result, notice task no return value, non-generic task.)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -