关键词搜索

源码搜索 ×
×

异常模拟

发布2021-01-30浏览366次

详情内容

package com.gblfy.controller;

import com.gblfy.service.ExceptionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("test")
public class Exception {
    private final static Logger logger = LoggerFactory.getLogger(Exception.class);

    @Resource
    private ExceptionService exceptionService;

    @GetMapping("/getException")
    public boolean getException() {
        boolean flag = false;
        try {
            flag = exceptionService.getException();
        } catch (java.lang.Exception e) {
            logger.error("接收      ----数据装换异常", e);
        }
        return flag;
    }
}

    package com.gblfy.service;
    
    public interface ExceptionService {
    
    
        public boolean getException() throws Exception;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    package com.gblfy.service.impl;
    
    import com.gblfy.service.ExceptionService;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Service;
    
    @Service
    public class ExceptionServiceImpl implements ExceptionService {
    
        private final static Logger logger = LoggerFactory.getLogger(ExceptionServiceImpl.class);
    
        @Override
        public boolean getException() throws Exception {
    
            try {
                logger.info("-----", 1 / 0);
                return true;
            } catch (Exception e) {
                logger.error("数据装换异常", e);
                throw e;
            }
        }
    
        public static void main(String[] args) {
    
            try {
                logger.info("-----", 1 / 0);
            } catch (Exception e) {
                logger.error("数据装换异常", e);
            }
    
            System.out.println("-------------------@@@");
        }
    }
    
    
      32
    • 33
    • 34
    • 35
    • 36

    相关技术文章

    最新源码

    下载排行榜

    点击QQ咨询
    开通会员
    返回顶部
    ×
    微信扫码支付
    微信扫码支付
    确定支付下载
    请使用微信描二维码支付
    ×

    提示信息

    ×

    选择支付方式

    • 微信支付
    • 支付宝付款
    确定支付下载