Verified Solution[pytorch/pytorch] [dynamo] Raising non-BaseException values causes graph break instead of TypeError
Sponsored Content
### ROOT CAUSE
The issue occurs because the function `_raise_exception_variable` in `symbolic_convert.py` does not handle non-BaseException raise operands by raising a TypeError, but instead uses `unimplemented()` which breaks the graph. This does not match CPython's behavior, where a TypeError is raised for such cases. The graph break prevents user `except TypeError` handlers from executing within the traced graph.
### CODE FIX
Change the function `_raise_exception_variable` in `symbolic_convert.py` to raise a TypeError for non-BaseException operands.
Specifically, replace:
```python
if not isinstance(value, BaseException):
return unimplemented("raise non-BaseException")
```
with:
```python
if not isinstance(value, BaseException):
raise TypeError(f"exceptions must derive from BaseException; got {type(value).__name__}")
```
This change ensures that non-BaseException raise operands are handled by raising a TypeError, consistent with CPython's behavior.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[StackOverflow/reactjs] Best way set up protected Route in react using JWT?
[StackOverflow/python] Update Pandas Series with Multiindex
[StackOverflow/rust] method not found in `&&(dyn PartialReflect + 'static)`