C Sharp (C#) - Exception Handling
You want to catch exceptions only if their message contains the word "critical" and log them. Which code snippet correctly uses a when clause to do this?
You want to catch exceptions only if their message contains the word "critical" and log them. Which code snippet correctly uses a when clause to do this?
when clause must have a boolean expression after it to filter exceptions.when (ex.Message.Contains("critical")). catch (Exception ex) if (ex.Message.Contains("critical")) { Log(ex); } uses invalid syntax with if. catch (Exception ex) { if (ex.Message.Contains("critical")) Log(ex); } uses if inside catch, not when. catch (Exception ex) when { ex.Message.Contains("critical"); Log(ex); } has invalid when syntax.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions