首页 > 解决方案 > 异常返回无

问题描述

我想在调用函数时捕获错误。例如,互联网已经消失。我这样做:

    def get_position(self) -> position.Position:
       result = position.Position()
       try:
           return result.json_parse(self.client.futures_position_information(symbol=SYMBOl))
       except Exceptione:
           print(f'err: GET_POSITION {e}')
           time.sleep(5)
           self.get_position()

互联网出现后。该函数返回无。我明白这是不正确的。怎么做才对?

标签: pythonexception

解决方案


不要递归调用函数

  def get_position(self) -> position.Position:
      while True:
          result = position.Position()
          try:
              return result.json_parse(self.client.futures_position_information(symbol=SYMBOl))
          except Exceptione:
              print(f'err: GET_POSITION {e}')
              time.sleep(5)

推荐阅读