Python Detect String Using Exception Handling