异常返回无

时间:2021-02-06 07:07:53

标签: python exception

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

    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()

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

1 个答案:

答案 0 :(得分:0)

不要递归调用函数

  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)