Complete the code to catch only ArgumentNullException exceptions.
try { string s = null; Console.WriteLine(s.Length); } catch (ArgumentNullException [1]) { Console.WriteLine("Null argument caught."); }
when (false) which never catches exceptions.The when clause with true means the catch block will always execute for ArgumentNullException.
Complete the code to catch exceptions only when the message contains 'timeout'.
try { // some code } catch (Exception ex [1] ex.Message.Contains("timeout")) { Console.WriteLine("Timeout error caught."); }
if instead of when in catch.The when keyword is used to filter exceptions based on a condition.
Fix the error in the catch block to properly use a when clause.
try { // code } catch (Exception ex [1] ex.Message == null) { Console.WriteLine("Message is null."); }
if instead of when.The correct keyword for filtering exceptions is when, not if or others.
Fill both blanks to catch InvalidOperationException only when the error code is 404.
try { // code } catch (InvalidOperationException ex [1] ex.HResult [2] 404) { Console.WriteLine("Not found error caught."); }
if instead of when.!= instead of ==.Use when to filter exceptions and == to compare the error code.
Fill all three blanks to catch exceptions when the message contains 'disk' and the error code is 1234.
try { // code } catch (Exception ex [1] ex.Message.Contains("disk") && ex.HResult [2] [3]) { Console.WriteLine("Disk error caught."); }
if instead of when.The when clause filters exceptions with a condition combining message and error code checks.