Complete the code to catch exceptions in an async method.
try { await SomeAsyncMethod(); } catch ([1] ex) { Console.WriteLine(ex.Message); }
You catch exceptions by specifying Exception in the catch block.
Complete the code to rethrow the caught exception preserving the stack trace.
try { await SomeAsyncMethod(); } catch (Exception ex) { [1]; }
throw ex; which loses the original stack trace.return instead of throwing.Use throw; to rethrow the exception preserving the original stack trace.
Fix the error in the async method signature to enable exception handling.
public async [1] SomeAsyncMethod() { throw new Exception("Error"); }
Async methods that do not return a value should return Task to allow awaiting and exception handling.
Fill both blanks to create a dictionary comprehension that filters exceptions by message length.
var errors = new Dictionary<string, string>(); foreach (var ex in exceptions) { if (ex.Message.Length [1] 10) { errors.Add(ex.Message, ex[2]); } }
The code filters exceptions with message length greater than 10 and adds them to the dictionary using the message as key.
Fill all three blanks to create a LINQ query that selects exception messages with inner exceptions.
var messages = exceptions.Where(ex => ex.[1] != null) .Select(ex => ex.[2]) .Where(msg => msg.[3]("error", StringComparison.OrdinalIgnoreCase)) .ToList();
This LINQ query filters exceptions that have an inner exception, selects their messages, and filters messages containing the word "error".