Broad or narrow try/except (Python)?
Unanimous. Anyone disagreeing with this in 2026 needs to log off.
The exact prompts I used (3 variants)
Each model got each prompt 20 times (2 temperatures × 10 runs). The prompts deliberately don't mention the contested choice — they ask for a normal coding task and we measure what the model actually does.
-
Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully. -
Write a Python function that parses an integer from a string and returns a default if parsing fails. -
Write a Python function that fetches a URL with `urllib.request` and returns the body, returning None on failure.
Who said what
The pundit panel.
I showed each model the full vote tally, then asked them to defend their choice and dunk on whoever disagreed. Receipts attached.
“Catching `except Exception` instead of `FileNotFoundError` and `json.JSONDecodeError` separately isn't error handling — it's a blindfold that swallows bugs you'll spend three days debugging in production.”
“If you pick broad exceptions in Python, you are basically confessing you prefer masking real bugs over handling expected failures, which is amateur-hour error handling with extra smugness.”
“Broad exceptions are amateur hour; NARROW wins because `except Exception` preserves real bugs while catching the specific failure you actually meant to handle.”
“Catching BROAD exceptions isn't error handling, it's just lazy bug-hiding that silences specific failures and makes your application impossible to debug.”
Show me the actual code (240 samples)
Claude Sonnet 4.6 — 60 samples click to expand
Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
## Reading JSON Files with Error Handling
Here's a robust function that reads and parses a JSON file with comprehensive error handling:
```python
import json
import logging
from pathlib import Path
from typing import Any
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
def read_json_file(file_path: str | Path) -> Any | None:
"""
Read and parse a JSON file from disk.
Args:
file_path: Path to the JSON file (string or Path object).
Returns:
Parsed JSON object (dict, list, str, int, float, bool, or None)
or None if an error occurs.
Raises:
No exceptions — all errors are handled gracefully and logged.
"""
path = Path(file_path)
try:
if not path.exists():
logger.error("File n
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
## Reading JSON Files with Error Handling
Here's a robust function that reads and parses a JSON file with comprehensive error handling:
```python
import json
import logging
from pathlib import Path
from typing import Any
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
def read_json_file(file_path: str | Path) -> Any | None:
"""
Read and parse a JSON file from disk.
Args:
file_path: Path to the JSON file (string or Path object).
Returns:
Parsed JSON object (dict, list, str, int, float, bool, or None),
or None if an error occurs.
Raises:
No exceptions — all errors are handled gracefully and logged.
"""
path = Path(file_path)
try:
if not path.exists():
logger.error("File
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
## Reading JSON Files with Error Handling
Here's a robust function that reads and parses a JSON file with comprehensive error handling:
```python
import json
import logging
from pathlib import Path
from typing import Any
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
def read_json_file(file_path: str | Path) -> Any | None:
"""
Read and parse a JSON file from disk.
Args:
file_path: Path to the JSON file (string or Path object).
Returns:
Parsed JSON object (dict, list, str, int, float, bool, or None)
or None if an error occurs.
Raises:
No exceptions are raised; errors are logged instead.
Examples:
>>> data = read_json_file("config.json")
>>> data = read_json_file(Path("/etc/app/set
… …and 57 more samples (across 3 prompt variants × 2 temperatures × 10 runs). Full data in the result JSON on GitHub.
GPT-5.4 — 60 samples click to expand
Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
from pathlib import Path
from typing import Any, Optional
def read_json_file(file_path: str) -> Optional[Any]:
"""
Read a JSON file from disk and return the parsed object.
Returns:
The parsed JSON object if successful, otherwise None.
"""
try:
path = Path(file_path)
if not path.exists():
print(f"Error: File not found: {file_path}")
return None
if not path.is_file():
print(f"Error: Not a file: {file_path}")
return None
with path.open("r", encoding="utf-8") as f:
return json.load(f)
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in file '{file_path}': {e}")
except PermissionError:
print(f"Error: Permission
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
from pathlib import Path
from typing import Any
def read_json_file(file_path: str | Path) -> Any:
"""
Read a JSON file from disk and return the parsed object.
Returns:
The parsed JSON content (dict, list, etc.), or None if an error occurs.
"""
try:
path = Path(file_path)
if not path.exists():
print(f"Error: File does not exist: {path}")
return None
if not path.is_file():
print(f"Error: Path is not a file: {path}")
return None
with path.open("r", encoding="utf-8") as f:
return json.load(f)
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in file '{file_path}': {e}")
except OSError as e:
print(f"Error: Could
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
from pathlib import Path
from typing import Any, Optional
def read_json_file(file_path: str) -> Optional[Any]:
"""
Read a JSON file from disk and return the parsed object.
Returns:
The parsed JSON data, or None if an error occurs.
"""
try:
with open(file_path, "r", encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
print(f"Error: File not found: {file_path}")
except PermissionError:
print(f"Error: Permission denied: {file_path}")
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in {file_path}: {e}")
except OSError as e:
print(f"Error reading file {file_path}: {e}")
return None
```
Example usage:
```python
data = read_json_file("con
… …and 57 more samples (across 3 prompt variants × 2 temperatures × 10 runs). Full data in the result JSON on GitHub.
GPT-5.4 mini — 60 samples click to expand
Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
from pathlib import Path
def read_json_file(file_path):
"""
Read a JSON file from disk and return the parsed object.
Parameters:
file_path (str or Path): Path to the JSON file.
Returns:
The parsed JSON object, or None if an error occurs.
"""
try:
with open(Path(file_path), "r", encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
print(f"Error: File not found: {file_path}")
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in {file_path}: {e}")
except OSError as e:
print(f"Error reading {file_path}: {e}")
return None
```
Example usage:
```python
data = read_json_file("config.json")
if data is not None:
print(data)
``` Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
def read_json_file(file_path):
"""
Read a JSON file from disk and return the parsed object.
Returns None if the file cannot be read or parsed.
"""
try:
with open(file_path, "r", encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
print(f"Error: File not found: {file_path}")
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in {file_path}: {e}")
except OSError as e:
print(f"Error reading {file_path}: {e}")
return None
```
Example usage:
```python
data = read_json_file("data.json")
if data is not None:
print(data)
``` Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
```python
import json
from typing import Any, Optional
def read_json_file(path: str) -> Optional[Any]:
"""
Read a JSON file from disk and return the parsed object.
Returns:
The parsed JSON object on success, or None if an error occurs.
"""
try:
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
print(f"Error: File not found: {path}")
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in {path}: {e}")
except OSError as e:
print(f"Error reading {path}: {e}")
return None
```
Example usage:
```python
data = read_json_file("config.json")
if data is not None:
print("Loaded JSON:", data)
``` …and 57 more samples (across 3 prompt variants × 2 temperatures × 10 runs). Full data in the result JSON on GitHub.
Gemini 2.5 Pro — 60 samples click to expand
Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
Of course! Here is a robust Python function that reads and parses a JSON file, complete with comprehensive, graceful error handling and a detailed explanation.
### The Python Function
This function is designed to be safe and informative. It anticipates common issues like the file not existing, not having read permissions, or containing invalid JSON.
```python
import json
import sys
from typing import Any, Optional
def read_json_file(file_path: str) -> Optional[Any]:
"""
Reads a JSON file from disk and returns the parsed object.
This function handles common errors gracefully, such as the file not
existing, permission errors, or the file containing malformed JSON.
It prints a user-friendly error message to standard error and returns None
in case of an error.
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
Of course! Here is a well-documented and robust Python function to read and parse a JSON file, complete with graceful error handling.
### The Function
This function, `read_json_file`, takes a file path as input. It attempts to open, read, and parse the JSON file. If any error occurs (e.g., the file doesn't exist, it's not valid JSON), it prints a helpful message and returns `None`.
```python
import json
import sys
from typing import Any, Optional
def read_json_file(file_path: str) -> Optional[Any]:
"""
Reads a JSON file from disk and returns the parsed object.
Handles common errors such as the file not being found, permission errors,
or the file containing invalid JSON.
Args:
file_path: The path to the JSON file.
Returns:
The parsed Python obj
… Write a Python function that reads a JSON file from disk and returns the parsed object, handling errors gracefully.
Of course! Here is a robust Python function that reads and parses a JSON file, complete with comprehensive error handling, type hints, and a detailed explanation.
### The Python Function
This function is designed to be safe and informative. It anticipates common issues like the file not existing, not having permission to read it, or the file containing invalid JSON.
```python
import json
import os
from typing import Any, Optional
def read_json_file(file_path: str) -> Optional[Any]:
"""
Reads a JSON file from disk and returns the parsed Python object.
Handles common errors such as the file not being found, permission errors,
and invalid JSON format.
Args:
file_path (str): The full path to the JSON file.
Returns:
Optional[Any]: The parsed Python
… …and 57 more samples (across 3 prompt variants × 2 temperatures × 10 runs). Full data in the result JSON on GitHub.
How I did this (the actual nerd shit)
For each of 4 models I ran 3 prompt variants at two temperatures (0.0 and 0.7), 10 runs each — 240 code samples total, cost $2.91.
Each output got fed through a fight-specific regex classifier.
For except-granularity the classifier looks for the specific signal in the output
(see the source — there's one function per fight, ~30 lines each).
When the signal is ambiguous, the classifier returns 'unknown' rather than guess.
Each model's vote = its modal classification across 60 runs. Confidence = Wilson 95% CI. Verdict = majority across models (ties reported as ties). Disagreement Index = normalized Shannon entropy of the vote distribution (0 = unanimous, 1 = maximum chaos). Leaderboard sorts by this.
The pundit quotes come from a follow-up call after the votes are in — each model gets the full tally and a per-model judgy prompt. I never edit the quotes.
Full walkthrough: the methodology page. Source: GitHub.
Open a PR with a new fight. I'll run it across all four models, write up the verdict, and add your name to the byline.
Submit via PR →