What is exception handling in C#?

Answer

C# uses structured exception handling with try/catch/finally blocks. try: code that might throw. catch: handles specific exceptions. finally: always executes (cleanup), whether or not an exception occurred. throw: throws an exception. Re-throw with context: throw; (preserves stack trace) vs throw ex; (resets stack trace — avoid). Best practices: (1) Catch specific exceptions, not the bare Exception (unless at the top level). (2) Never swallow exceptions silently (catch { }). (3) Use finally or using for cleanup — not catch. (4) Don't use exceptions for normal control flow — they're expensive. (5) Include meaningful messages: throw new ArgumentNullException(nameof(param), "Param cannot be null");. (6) Create custom exceptions for domain-specific errors by inheriting from Exception. (7) when clause for conditional catch: catch (HttpException ex) when (ex.StatusCode == 404).