Pages

Topics

Tools

↑↓navigate↵openescclose

C# guides

Every published C# guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest C# guides

Illustration of a custom exception class in C# with properties and serialization attributes, representing structured error handling.
C#

Creating Custom Exceptions in C#

Learn how to define a custom exception in C# that carries precise error context, preserves inner exceptions, and supports serialization across process boundaries.

C#Exception HandlingCustom ExceptionsError Handling
Illustration of multiple catch blocks in C# handling different exception types, showing ordered blocks and a filter condition.
C#

C# Multiple Catch Blocks: Syntax and Ordering

Learn how to use multiple catch blocks in C# to handle different exception types, order them by specificity, use exception filters, and avoid common pitfalls.

C#Exception Handlingtry-catchError Handling
Illustration of a C# exception filter using catch when to conditionally handle exceptions.
C#

C# catch when: Using Exception Filters

Learn how to use the C# catch when clause to filter exceptions with precise conditions and understand how it differs from traditional catch blocks.

C#exception handlingexception filterserror handling
Illustration of a C# exception filter concept showing a catch block with a condition.
C#

Using C# Exception Filters to Control Error Handling

c# exception filter: Learn how C# exception filters work, when to use them, and how they differ from traditional catch blocks.

C#Exception HandlingException FiltersError Handling
A visual comparison of throw and throw ex in C# showing how stack trace information is preserved or lost.
C#

C# throw vs throw ex: Stack Trace Differences Explained

c# throw vs throw ex: Understand the difference between throw and throw ex in C#, how each affects the stack trace, and when to use which for reliable error handling.

C#Exception HandlingStack TraceDebugging
Illustration of throwing an exception in C# with a custom exception class and stack trace preservation.
C#

C# Throw Exception: Syntax and Correct Usage

Learn how to throw exceptions in C#, including correct syntax, custom exception types, rethrowing, and common pitfalls.

C#exception handlingthrow statementcustom exceptions
Illustration of the C# throw keyword with an exception being thrown from a method to a caller.
C#

C# Throw Keyword: Syntax, Rethrowing, and Filters

Practical guide to the C# throw keyword: syntax, rethrowing exceptions, exception filters, custom exceptions, and performance tradeoffs.

C#Exception HandlingthrowRethrowing Exceptions
Diagram showing a try-catch-finally block with a finally block executing cleanup code regardless of exceptions.
C#

C# Finally Block: Execution Guarantees and Usage

Learn how the C# finally block guarantees cleanup runs, how it interacts with return and exceptions, and when it does not execute.

C#exception handlingtry-catch-finallyresource cleanup
Illustration showing the flow of try, catch, and finally blocks in C# exception handling.
C#

C# Try Catch Finally: How the Blocks Actually Behave

Understand how try, catch, and finally blocks interact in C#, when the finally block runs, and how to avoid common exception-handling mistakes.

exception handlingC# syntaxtry-catch-finallyerror handling
Illustration of a C# try-catch block showing an exception being caught and handled with a finally block for cleanup.
C#

C# try catch: Syntax, Usage, and Pitfalls

c# try catch: Learn the practical syntax and behavior of the C# try-catch statement, including exception filters, finally, performance implications, and common mistakes.

exception handlingtry-catchC# error handlingfinally block