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
2017-09-18 01:52
295 查看
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?
I get following error with invalid path:
This exception seems to be comming from FieldFilter which is jar's class.
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.
相关文章推荐
- 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
- java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
- java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
- java.sql.SQLSyntaxErrorException:length must be specified in type definition:VARBINARY
- Java异常处理:java.lang.ClassCastException: JSON keys must be strings
- 微信证书 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
- java.lang.IllegalArgumentException: At least one handler method must be found in class [class SayThr
- java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=Aict/listPagedAict.action
- [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] The child node "db_driver" at path "fos_user" must be configured.
- java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.
- Android开发出现Java.lang.IllegalStateException的原因;Target host must be null,or set in parameters
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- 在发送请求时 java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=n
- Windows下启动eclipse出现JRE or JDK must be available in order to run Eclipse.No Java virtual machine was
- Translating SQLException with SQL state '42000', error code '1064', message [You have an error in yo
- java.lang.IllegalArgumentException: System memory ... must be at least ... Please use a larger heap
- Android报错:Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
- java.io.InvalidClassException:PublishInfMsg(类名); local class incompatible: 解决方法
- A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/