Results for “error handling”
Small, practical examples. Search by task or narrow things down below.
Compare bounded floating-point results with a tolerance
TypeScript: Use an absolute error threshold for values known to be near one.
TypeScript✓ Tested
Compare floating-point results with a tolerance
Java: For this bounded example, compare the absolute difference against a chosen error threshold.
Java✓ Tested
Compute a simple XOR checksum
C: XOR all payload bytes into one byte to demonstrate a basic error-detection field.
C✓ Tested
Copy a file in bounded binary chunks
C: Check read, write, and close errors while copying without loading the entire file.
C✓ Tested
Create a file without overwriting an existing one
Python: Use exclusive creation mode and handle FileExistsError explicitly.
Python✓ Tested
Delete a known temporary file if present
Java: deleteIfExists returns whether a file was removed and still reports other I/O errors.
Java✓ Tested
Dispatch a one-character serial command
Arduino / C: A switch provides explicit handling for accepted and unknown commands.
Arduino / C✓ Tested
Measure a small seekable binary file
C: Seek to the end and inspect ftell, checking both operations for errors.
C✓ Tested
Pair corresponding array items by position
JavaScript: Validate equal lengths before zipping when missing counterparts would be an error.
JavaScript✓ Tested
Pair corresponding array items by position
TypeScript: Validate equal lengths before zipping when missing counterparts would be an error.
TypeScript✓ Tested
Pair corresponding collection elements
C#: Zip stops at the shorter sequence, so validate lengths separately if mismatches are an error.
C#✓ Tested
Parse a complete integer without exceptions
C++: from_chars reports both an error code and the first unconsumed character.
C++✓ Tested