Interview Question

Exception handling in C#?

Use typed catch blocks for recoverable failures and finally for required cleanup.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

C# exception handling uses try, catch, finally, and throw to report and handle exceptional conditions. • catch selects handlers by compatible exception type and optional filter. • finally runs as control leaves the try statement, including during exception propagation. • Catch only exceptions the current code can handle meaningfully.

💡 C# Example

try { int value = int.Parse("not-a-number"); } catch (FormatException) { Console.WriteLine("Invalid number"); }

Output

Invalid number

⚡ Quick Revision

Use typed catch blocks for recoverable failures and finally for required cleanup.