Print Page | Close Window

Catching TaskCanceledException

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3995
Printed Date: 05-May-2024 at 3:35pm


Topic: Catching TaskCanceledException
Posted By: gregweb
Subject: Catching TaskCanceledException
Date Posted: 20-Feb-2013 at 10:34am
In StaffingResourcePhoneListViewModel, there is an Add() method which calls:

await _dialogManager.ShowDialogAsync(phoneTypeSelector, DialogButtons.OkCancel);

Shouldn't this be in a Try-Catch to catch a TaskCanceledException? It will throw this if the user clicks on cancel in the Phone type dialog.

Greg



Replies:
Posted By: smi-mark
Date Posted: 20-Feb-2013 at 12:07pm
Doesn't the ErrorHandler catch it?


Posted By: mgood
Date Posted: 20-Feb-2013 at 2:00pm
There is no logic to be executed if the user decides to cancel, so what are you going to put in the catch? The TaskCanceledException will bubble up as an unhandled exception and ultimate ignored in the ErrorHandler. If you don't like unhandled exceptions, then you would put a try/catch around it and hand the exception directly to the ErrorHandler, where it will get ignored. 


Posted By: gregweb
Date Posted: 21-Feb-2013 at 7:37am
OK, I get it now:

The Cocktail BootstrapperBase hooks into Application.UnhandledException so any unhandled exceptions are passed to ErrorHandler.HandleError which checks the type of the exception and ignores it if it is a TaskCanceledException.

Works for me.

Greg



Print Page | Close Window