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的桥梁,源代码编译 ...
随机推荐
- 【ABAP系列】SAP ABAP常用函数总结第一篇
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP常用函数总结第一 ...
- 状压DP : [USACO06NOV]玉米田
玉米田 内存限制:128 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:文本比较 题目描述 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ ...
- 应用安全 - Windows操作系统 - 漏洞 - 汇总
FTP弱密码 将FTP服务器的密码更改为强密码 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO #禁止匿名登录 重启ftp服务 Windows匿名用户整改 ...
- C#将字符串Split()成数组
string str="aaajbbbjccc";string[] sArray=str.Split('j');foreach(string i in sArray) Respon ...
- HTML5--sessionStorage、localStorage、manifest
sessionStroage: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- 小Q的棋盘 (贪心)
小Q的棋盘 (贪心) 题目 洛谷传送门 做法 显然这是一棵树(这个就不多bb了,树的性质) 很容易发现一个性质,如果一条链走完,我们必须回头再走一次那条链(或一部分)才可以走到更多的点 所以为了减少这 ...
- 学习servlet时出现的一些问题
此篇用来记录学习servlet时遇到的一些问题,谨防以后再犯. 问题1.导入的web项目,servlet中导入的包名报错. (1)缺少相关包,推荐一个网站下载jar包很方便http://mvnrepo ...
- BZOJ 1683.City skyline 城市地平线
传送门 从左到右扫一遍,考虑什么时候会和之前形成同一幢房子从而不用统计 显然是当前的高度和之前某个点高度相同,并且它们之间没有更矮的建筑 考虑用一个单调栈维护一个单调上升的房子轮廓,然后对于扫到的每一 ...
- 专题:性能调优之工具---perf
1. Linux Perf简介 1.1 Perf是什么 Perf 是内置于Linux 内核源码树中的性能剖析(profiling)工具.它基于事件采样原理,以性能事件为基础,支持针对处理器相关性能指标 ...
- 靶场练习--sqli(3&4)
第三关 先解决一下第二关遗留下来的问题,嘻嘻.看来数据库原理应当过一遍~ 1.首先判断是否有SQL注入,然后再看是数字型.字符型.发现这里是字符型. 2.order by 查询字段数,记得后面要加一个 ...