zoukankan      html  css  js  c++  java
  • Java JsonPath grab InvalidPathException in code, you must be catching Java 7's java.nio.file.InvalidPathException instead of JsonPath's com.jayway.jsonpath.InvalidPathExceptio


    I am using JsonPath and am able to parse my data and get the values when the path provided is correct.

    However when I provide an incorrect path (user input) the program terminates. I dont want that to happen. Is there anyway for me to catch this exceptions and continue with the next steps?

    try
            {
                String value = JsonPath.read(jsonText, jsonPath);
    
                System.out.println(value);
            }
            catch(InvalidPathException e)
            {
                System.out.println("ERROR<InvalidPathException>: "+e.getMessage());
            }
    

    I get following error with invalid path:

    Exception in thread "main" com.jayway.jsonpath.InvalidPathException: invalid path
    at com.jayway.jsonpath.internal.filter.FieldFilter.filter(FieldFilter.java:59)
    at com.jayway.jsonpath.JsonPath.read(JsonPath.java:182)
    at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
    at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
    at office.jsonPathparse.main(jsonPathparse.java:37)
    

    This exception seems to be comming from FieldFilter which is jar's class.


    If I understood you correctly and your catch block isn't being executed, you must be catching Java 7's java.nio.file.InvalidPathException instead of JsonPath's com.jayway.jsonpath.InvalidPathException. Double check your import statements.
  • 相关阅读:
    bzoj3622: 已经没有什么好害怕的了
    BSGS
    LOJ#2320 生成树计数
    ??? cliquers
    生成函数
    洛谷P5206 数树
    01分数规划
    差分约束系统
    51nod1238 最小公倍数之和 V3
    51nod1237 最大公约数之和 V3
  • 原文地址:https://www.cnblogs.com/timssd/p/7538990.html
Copyright © 2011-2022 走看看