FIND YOUR NEXT FEW LINES

Results for “except”

Small, practical examples. Search by task or narrow things down below.

22 snippets foundClear filters
PythonFile operations & archives

Clean up a temporary directory automatically

Python: Use TemporaryDirectory as a context manager so cleanup also happens after exceptions.

Python✓ Tested
C#Collections & data structures

Find values missing from another collection

C#: Except removes duplicates as it calculates the set difference.

C#✓ Tested
C#JSON & binary formats

Handle malformed JSON

C#: Catch JsonException for malformed JSON without swallowing unrelated failures.

C#✓ Tested
C#Asynchronous work & URI handling

Limit concurrent access with SemaphoreSlim

C#: Release the semaphore in finally so exceptions cannot leave it permanently acquired.

C#✓ Tested
JavaNumbers & dates

Parse an integer safely

Handle invalid Java integer input with NumberFormatException.

Java✓ Tested
PowerShellFunctions & parameter validation

Preserve a failure after local cleanup

PowerShell: A bare throw inside catch rethrows the current exception.

PowerShell✓ Tested
TypeScriptSafe data handling

Read a nested optional value

Avoid dereferencing a missing nested object.

optional chaining✓ Tested
C++Filesystem operations

Rename a known file through filesystem

C++: filesystem::rename reports an error by exception when the operation fails.

C++✓ Tested
C++Ownership & optional values

Run cleanup through a scoped destructor

C++: A stack object’s destructor runs when its scope exits, including normal exception unwinding.

C++✓ Tested
C#Strings

Try parsing an integer

Use TryParse to avoid exceptions for invalid C# integer input.

C#✓ Tested