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? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -