Python Detect String Using Exception Handling In Javascript