Closed laventnc closed 3 years ago
You can do that to catch all exceptions at the root level. I don't have strong opinions.
My only suggestion is that the DoWork
method should be clean which simply creates a DI scope and call a method in a service.
For me, I usually catch exceptions inside each child service. But it's just a preference.
Awesome, I appreciate the insight!
For instance, a few of my jobs call internal web services/applications and I want to cleanly handle unlikely exceptions (such as a System.Net.Http.HttpRequestException).
I currently have an abstract base class
DomainCronJob : CronJobService
, which calls an abstract methodRun( CancellationToken cancellationToken );
. As expected, uncaught exceptions bubble up to the CrobJobService call toawait DoWork( cancellationToken )
. I'm a little new to hosted services and was wondering if there was a reason you left out a generictry { await DoWork(...) } catch (Exception) {}
from this call / what you think the best course of action would be.