【问题标题】:Catching python execution error in matlab在matlab中捕获python执行错误
【发布时间】:2019-04-29 21:28:24
【问题描述】:

我的 matlab 程序将生成一个 python 文件并启动它。由于各种原因,有时生成的python文件会出错。现在没有时间调试我希望能够在 python 文件执行失败时在 matlab 中捕获的部分,因此我可以使用不同的随机输入重新运行该函数。

那么我如何检测启动的 python 文件上的错误。谢谢!

【问题讨论】:

    标签: python matlab


    【解决方案1】:

    只需像这样使用try-catch-end

    while true
      try
        yourcodeofpython;
        break;
      catch e
        if isa(e,'matlab.exception.PyException')
          % e.message % or something to log the error
        end
        continue;
      end
    end
    

    只有在 Python 完成时才会结束,如果出现异常将重新启动。 isa(e,'matlab.exception.PyException')是检查是否是Python Exception。

    Official Docs about this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 2019-02-20
      • 2011-02-10
      相关资源
      最近更新 更多