zoukankan      html  css  js  c++  java
  • [Java基础]Java异常捕获

    在Java中,异常分为二类:Error和Exception, Exception是运行时异常,Error是JVM内部错误,捕获Exception没法捕获Error

    Throwable
     |      |
    Error   Exception
            |
            RuntimeException

    今天我在项目中就遇到了一个问题,如下:

    try {
                        //更新log
                        PullUpdateLogVO vo = new PullUpdateLogVO();
                        vo.setNotifyId(notification.getNotifyId());
                        vo.setQueryStatus(pullDataResult != null ? pullDataResult.getStatus() : 3);
                        vo.setQueryTime(queryTime);
                        vo.setRespSerial(pullDataResult != null ? pullDataResult.getRespSerial() : "");
                        vo.setUserid(notification.getUserid());
                        String res = getValidateService().pullUpdate(vo);
                        logger.info(String.format("更新任务查询状态成功: log = %s", res));
                    } catch (Exception ex) {
                        logger.warn(String.format("更新任务查询状态失败:ex=%s", ex.getMessage()));
                    }

    打印出异常信息,如下图所示:

    Exception in thread "Mq-MqQueueExcutorServiceNew-DataChannel-PullDataNotify-104-3" java.lang.NoSuchMethodError: com.ppdai.cbd.thirdparty.pulldata.common.request.PullUpdateLogVO.setUserid(Ljava/lang/Integer;)V
        at com.ppdai.realtime.datachannel.pullservice.PullNotificationDispatchService.dispatchNotification(PullNotificationDispatchService.java:122)
        at com.ppdai.realtime.datachannel.mq.service.MessageQueueConsumer.onMessageReceived(MessageQueueConsumer.java:51)
        at com.ppdai.infrastructure.mq.client.biz.MqQueueExcutorService.doMessageReceived(MqQueueExcutorService.java:461)
        at com.ppdai.infrastructure.mq.client.biz.MqQueueExcutorService.doDealMsg(MqQueueExcutorService.java:408)
        at com.ppdai.infrastructure.mq.client.biz.MqQueueExcutorService.handleMessage(MqQueueExcutorService.java:369)
        at com.ppdai.infrastructure.mq.client.biz.MqQueueExcutorService.access$600(MqQueueExcutorService.java:48)
        at com.ppdai.infrastructure.mq.client.biz.MqQueueExcutorService$3.run(MqQueueExcutorService.java:308)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    NoSuchMethodError就是典型的JVM内部错误,属于Error的范畴,一般这种问题编译器就应该解决,Java Class编译文件class文件函数找不到错误。Error类层次如下:

     java.lang.Object


    解决办法:1.将捕获Exception改成捕获Throwable 2.另一种将依赖包类添加对应方法
    欢迎关注Java流水账公众号
  • 相关阅读:
    一条Sql的Spark之旅
    Redis学习笔记:Redis在C#中的使用
    MySQL_表操作
    git上传新项目到coding
    Jenkins 安装 on centos7
    day 36
    表单生成器(Form Builder)之表单数据存储结构mongodb篇
    ORA-16032和ORA-07286 LOG_ARCHIVE_DEST_1没生效
    SQL查询小案例
    mysql从5.6升级到5.7后出现 Expression #1 of ORDER BY clause is not in SELECT list,this is incompatible with DISTINCT
  • 原文地址:https://www.cnblogs.com/guofu-angela/p/10594677.html
Copyright © 2011-2022 走看看