Python Detect String Using Exception Handling In C