如何使用try-catch来捕获外部代码的分段错误?

时间:2017-12-04 04:47:40

标签: matlab try-catch

我打电话给外部执行官。使用MATLAB代码中的system()命令的文件(不是由我编写的)。由于某些原因,外部文件s / t给出了Segmentation fault错误,如果我再次运行代码,它就会被修复。

因此,正如我们在其他语言中所做的那样,我使用try catch来捕获错误,而不是停止整个过程。这是我写的:

flag = false;
while(~flag)
    try
        system('….');
        flag = true;
    catch MExc
        flag = false;
    end
end

但是,它没有发现错误。如何解决?

1 个答案:

答案 0 :(得分:0)

我怀疑你在Matlab中调用时可以捕获外部应用程序抛出的异常(事实上,毫无疑问,我确定,但句子更优雅)。无论如何,据我所知,一个没有错误关闭的应用程序应返回class Entity { @Id int id Person person } class Person { String name } def "should use CustomValueComparator for Person when Person is mapped as Value"(){ given: def javers = JaversBuilder.javers().registerValue(Person, { l, r -> if (r.name == null) return true else return r.name.equals(l.name) }).build() def personLeft = new Person(name: "john") def personRight = new Person() def eLeft = new Entity(id:1, person: personLeft) def eRight = new Entity(id:1, person: personRight) expect: javers.compare(eLeft, eRight).changes.size() == 0 javers.compare(eRight, eLeft).changes.size() == 1 javers.getTypeMapping(Person) instanceof ValueType } def "should used CustomValueComparator for Strings"(){ given: def javers = JaversBuilder.javers().registerValue(String, { l, r -> if (r == null) return true else return r.equals(l) }).build() def personLeft = new Person(name: "john") def personRight = new Person() expect: javers.compare(personLeft, personRight).changes.size() == 0 javers.compare(personRight, personLeft).changes.size() == 1 javers.getTypeMapping(Person) instanceof ValueObjectType } 等于ExitCode

幸运的是,0函数将该值作为其第一个输出参数(official documentation)返回,因此请尝试使用以下代码:

system