About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Dealing with Errors

Tasks can execute arbitrary code, which obviously can also fail. How do exceptions thrown on tasks manifest themselves if they remain unhandled? Before discussing that, let’s review what happens when regular threads are used:

new Thread(() => {    throw new InvalidOperationException("Oops!");}).Start();

This causes the process to terminate because of the unhandled exception, ignoring the behavior in .NET 1.0 where this wasn’t the case. When working with threads, you must protect your threads against unhandled exceptions right inside the thread’s logic (of course, subject to the desired scrutiny): Don’t handle what you can’t deal with!

What you should remember from this is where a thread’s exceptions ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required