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.
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类加载器,报异常java.nio.file.InvalidPathException
String path = Label.class.getClassLoader().getResource("").getPath(); /F:/idea-Java/ImageD ...
- java.io.StreamCorruptedException: invalid type code: AC错误的解决方法
问题描述: 在向一个文件写入可序列化对象时,每次只想向文件的末尾添加一个可序列化的对象,于是使用了FileOutputStream(文件名,true)间接的构建了ObjectOutputStream流 ...
- Java Server returned HTTP response code: 401
今天写一个小功能需要通过http请求获取一些返回数据,但是在登陆时是需要进行用户名和密码的校验的.写好之后请求,返回异常Java Server returned HTTP response code: ...
- Java会出现"unreachable code"错误的几个例子
public class exam { static int num=5; static int m1(){ try{ num=6; throw new NullPointerException(); ...
- [java bug记录] java.util.zip.ZipException: invalid code lengths set
1. 描述:将代码迁移到maven工程,其中用ZipInputStream读取/src/main/resources下的zip文件时报错:“java.util.zip.ZipException: in ...
- [转]Native Java Bytecode Debugging without Source Code
link from:http://www.crowdstrike.com/blog/native-java-bytecode-debugging-without-source-code/index.h ...
- java was started but exit code =-805306369
打开STS 时报 java was started but exit code =-805306369这个错,一个页面. 原因我把STS里面的默认jdk换成了7.但是STS的ini文件里依赖的 ...
- 阿里巴巴 fastjson-1.2.12.jar json解析异常java.lang.ClassFormatError: Invalid method Code length 66865 in class file com/alibaba/fastjson/serializer/ASMSerializer_6_UserKdlb
承接上篇:fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:1 ...
- 小师妹学JVM之:java的字节码byte code简介
目录 简介 Byte Code的作用 查看Byte Code字节码 java Byte Code是怎么工作的 总结 简介 Byte Code也叫做字节码,是连接java源代码和JVM的桥梁,源代码编译 ...
随机推荐
- iframe父页面和子页面高度自适应
父页HTML: <iframe id="mainframe" name="mainframe" style="width:100%;&quo ...
- EasyUI在子tab基础上再打开新的tab标签页
var title = "xxxx"; var content = '<iframe scrolling="auto" frameborder=" ...
- Pytest+Allure2+Jenkins搭建
前置: (1)安装Python3(这里版本为3.7) (2)搭建Jenkins环境 一.安装pytest 直接使用pip安装(这里由于笔者的环境同时安装了Python2和Python3,所以在pyth ...
- javaScript Map
} } } vertices.push(v); adjList.set ...
- angularJS拦截路由
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams)
- 前端webpack & vue
地址 : https://blog.csdn.net/jiang7701037
- Java中的容器(集合)之HashMap源码解析
1.HashMap源码解析(JDK8) 基础原理: 对比上一篇<Java中的容器(集合)之ArrayList源码解析>而言,本篇只解析HashMap常用的核心方法的源码. HashMap是 ...
- java虚拟机笔记-1
java虚拟机学习笔记 Java技术的核心就是Java虚拟机,因为所有的Java程序都在虚拟机上运行.Java程序的运行需要Java虚拟机.Java API和Java Class文件的配合.Java虚 ...
- 10、numpy——位运算
NumPy 位运算 NumPy "bitwise_" 开头的函数是位运算函数. NumPy 位运算包括以下几个函数: 函数 描述 bitwise_and 对数组元素执行位与操作 b ...
- go 上下文context
go控制并发有两种经典的方式,一种是WaitGroup,另外一种就是Context WaitGroup这种方式是控制多个goroutine同时完成 func main() { var wg sync. ...