DAGDA SEARCH | Back to results | Support

Illegal raise — CodeQL query help documentation

Source: https://codeql.github.com/codeql-query-help/python/py-illegal-raise/

Illegal raise

ID: py/illegal-raise
Kind: problem
Security severity: 
Severity: error
Precision: very-high
Tags:
   - quality
   - reliability
   - error-handling
Query suites:
   - python-code-quality.qls
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

If the object raised is not a legal Exception class or an instance of one, then a TypeError will be raised instead.

Legal exception classes are:

Recommendation

Change the expression in the raise statement to be a legal exception.

Example

#Cannot raise an int, even if we want to
def raise_int():
    #Will raise a TypeError
    raise 4

References