如何使用自定义异常处理API错误

2024-10-02 00:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

    # define Python user-defined exceptions
class Error(Exception):
   """Base class for other exceptions"""
   pass
class NotTranslated(Error):
   """Raised when the input value is zero"""
   pass
try:
   test_string ="ok ਜੌਨ ਲੂਮਰ ਇੱਕ ਬਲੌਗਰ ਅਤੇ ਪੋਡਕੇਸਟਰ ਹੈ ਜਿਸਦੀ ਵੈਬਸਾਈਟ ਸਾਰੀਆਂ ok"
   res = test_string.split()
   for i in res:
    blob = TextBlob(i)
    print(blob.translate(to='en'))
   raise NotTranslated
except NotTranslated:
   print("Not Translated,!")
   print()

**我正在使用文本块翻译混合语言,有时会抛出API错误“未翻译”我想在try块中处理此问题,到目前为止,我已尝试过此方法,但未获得任何高度赞赏的帮助**


Tags: testforstringresokerrorpassblob

热门问题