Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- AppDomain.CurrentDomain.FirstChanceException += (object obj, FirstChanceExceptionEventArgs args) => {
- Console.WriteLine ("First chance exception ");
- args.Dump();
- };
- AppDomain.CurrentDomain.UnhandledException += (object obj, UnhandledExceptionEventArgs args) => {
- Console.WriteLine ("Unhandled exception ");
- };
- TaskScheduler.UnobservedTaskException += (object obj, UnobservedTaskExceptionEventArgs args) => {
- Console.WriteLine ("Unobserved exception");
- };
- try
- {
- //DoStuff().Wait(); // Observed
- DoStuff(); // Unobserved - Generates a FirstChanceException and an UnobservedTaskException (after several seconds).
- }
- catch (Exception ex)
- {
- Console.WriteLine ("An Observed task.");
- }
- }
- async Task DoStuff()
- {
- Task t = Task.FromResult(1);
- await t;
- throw new ArgumentException();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement