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. Oracle客户端和服务端的区别

    转载:https://blog.csdn.net/qq_22558507/article/details/75220224 随着Oracle技术领域应用越来越广泛,现在就关于oracle客户端配置极其 ...

  2. 牛客 打印N个数组整体最大的Top K

    题目链接:https://www.nowcoder.com/practice/5727b69bf80541c98c06ab90cf4c509e?tpId=101&tqId=33102& ...

  3. MySQL 查询语句--------------进阶9:联合查询

    #进阶9:联合查询 /* union 联合 合并:将多条查询语句的结果合并成一个结果 语法: 查询语句1 union 查询语句2 union..... 应用场景:要查询的结果来自于多个表,且多个表没有 ...

  4. Convolutional Neural Networks(4):Feature map size,Padding and Stride

    在CNN(1)中,我们用到下图来说明卷积之后feature maps尺寸和深度的变化.这一节中,我们讨论feature map size, padding and stride. 首先,在Layer1 ...

  5. urllib.parse解析链接

    1. urlparse() 解析链接,注意,返回值比3多一个params的属性 from urllib.parse import urlparse result = urlparse('http:// ...

  6. maven基础--IDEA集成

    创建项目 构建项目 查找依赖 依赖范围 provided:已提供依赖范围.编译和测试有效,运行无效.如servlet-api,在项目运行时,tomcat等容器已经提供

  7. HashSet -无序,不重复集合

    package cn.learn.collection.Set; import java.util.Objects; public class IsPerson { private int age; ...

  8. Synchronized 详解

    为了方便记忆,将锁做如下的分类 一.对象锁 包括方法锁(默认锁对象为this,当前实例对象)和同步代码块锁(自己指定锁对象) 1.代码块形式:手动指定锁定对象,也可是是this,也可以是自定义的锁 p ...

  9. Netty核心组件介绍及手写简易版Tomcat

    Netty是什么: 异步事件驱动框架,用于快速开发高i性能服务端和客户端 封装了JDK底层BIO和NIO模型,提供高度可用的API 自带编码解码器解决拆包粘包问题,用户只用关心业务逻辑 精心设计的Re ...

  10. [暑假集训Day2T3]团建活动

    个人认为这周题中较难的一道. 题意大概为:给定一张N个点M条边的无向图,求出无向图的一棵最小生成树,满足一号节点的度数不超过给定的整数K.保证 N <= 20 首先用map存取节点,之后抛去1号 ...