【问题标题】:Keep program running after decode_json() errordecode_json() 错误后保持程序运行
【发布时间】:2013-04-26 15:05:07
【问题描述】:

decode_json() 当参数不是有效的 json 时终止我的程序。如何保持程序运行并处理错误?

例子:

#!/usr/bin/perl -w

use strict;
use JSON;

my      $json='<html></html>';
my      $ticker=decode_json($json);
print $json;

应执行最后一次打印。

【问题讨论】:

标签: json perl


【解决方案1】:

这似乎是将decode_json() 包装在try catch block 中的最佳示例。

这样做可以让你继续执行,同时也为处理错误打开了大门,这样你就可以对发生错误的情况有特定的响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多