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的更多相关文章

  1. 使用java类加载器,报异常java.nio.file.InvalidPathException

    String path = Label.class.getClassLoader().getResource("").getPath(); /F:/idea-Java/ImageD ...

  2. java.io.StreamCorruptedException: invalid type code: AC错误的解决方法

    问题描述: 在向一个文件写入可序列化对象时,每次只想向文件的末尾添加一个可序列化的对象,于是使用了FileOutputStream(文件名,true)间接的构建了ObjectOutputStream流 ...

  3. Java Server returned HTTP response code: 401

    今天写一个小功能需要通过http请求获取一些返回数据,但是在登陆时是需要进行用户名和密码的校验的.写好之后请求,返回异常Java Server returned HTTP response code: ...

  4. Java会出现"unreachable code"错误的几个例子

    public class exam { static int num=5; static int m1(){ try{ num=6; throw new NullPointerException(); ...

  5. [java bug记录] java.util.zip.ZipException: invalid code lengths set

    1. 描述:将代码迁移到maven工程,其中用ZipInputStream读取/src/main/resources下的zip文件时报错:“java.util.zip.ZipException: in ...

  6. [转]Native Java Bytecode Debugging without Source Code

    link from:http://www.crowdstrike.com/blog/native-java-bytecode-debugging-without-source-code/index.h ...

  7. java was started but exit code =-805306369

       打开STS 时报  java was started but exit code =-805306369这个错,一个页面. 原因我把STS里面的默认jdk换成了7.但是STS的ini文件里依赖的 ...

  8. 阿里巴巴 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 ...

  9. 小师妹学JVM之:java的字节码byte code简介

    目录 简介 Byte Code的作用 查看Byte Code字节码 java Byte Code是怎么工作的 总结 简介 Byte Code也叫做字节码,是连接java源代码和JVM的桥梁,源代码编译 ...

随机推荐

  1. 认识requests库,以及安装方法

    1.学习requests库有什么意义 1)对我来说,我是测试人员,我用它来解决HTTP接口自动化测试 2)写爬虫需要用到requests 3)如果是开发人员,需要些接口,了解requests有助于掌握 ...

  2. Vue CLI UI:Vue开发者必不可少的工具

    突然发现一个Vue cli 比较好用的工具,一个可视化图形界面方便你去创建.更新和管理Vue项目.这里分享2个作者写得比较好的文章 https://codeseeding.com/portal.php ...

  3. 【Jmeter】利用Jmeter+ant+Jenkins 搭建 接口&性能测试 持续集成平台

    https://www.jianshu.com/p/6ab73a95d53e https://yq.aliyun.com/articles/664329

  4. IDEA永久破解方法

    链接: https://pan.baidu.com/s/1a1pMOP6rMrh-wJdUFSCqAw 提取码: 46cx 复制这段内容后打开百度网盘手机App,操作更方便哦

  5. 【五一qbxt】day4 数论知识

    这些东西大部分之前都学过了啊qwq zhx大概也知道我们之前跟着他学过这些了qwq,所以: 先讲新的东西qwq:(意思就是先讲我们没有学过的东西) 进制转换 10=23+21=1010(2) =32+ ...

  6. 【接口工具】接口抓包工具之Charles

    上篇我们讲了Fiddler,Fiddler是用C#开发的,所以Fiddler不能在Mac系统中运行,没办法直接用Fiddler来截获MAC系统中的HTTP/HTTPS, Mac 用户怎么办呢? 1.F ...

  7. 浅谈XML涉及到的常见技术(编写+解析)

    xml:即可扩展标记语言,用于描述关系型数据,也经常用作软件的配置文件:     1,编写xml文档一般基于一个约束文档,该文档用于规定xml的书写规范,常用的约束技术有        (1)XML ...

  8. 远程连接不上centos的mysql的解决方法

    1.防火墙没有开放3306端口 centos 有两种防火墙 FirewallD和iptables防火墙 centos7 使用的是FirewallD防火墙. 1.FirewallD防火墙开放3306端口 ...

  9. NGUI的滚动条的制作(scroll bar script)

    一,我们添加一个sprite,添加一个box collider,然后添加一个scroll bar script,我们来看看scroll bar script的属性 看到background和forgr ...

  10. MySQL数据库使用xtrabackup备份实现小例子

    关于MySQL数据库的备份的工具和方式也比较多,本文只简单介绍一些我司一个平台的备份方案.Xtrabackup是由percona开源的免费数据库热备份软件,但是只能对InnoDB数据库和XtraDB存 ...