Idea 常用代码块

一、背景

在开发过程有一些常用的代码块,为了方便我们可以把它配置成模板,利用快捷短句快速构建,可以为我们省去很多重复的开支。

二、常用代码块

2.1 异常处理

快捷键

tryc

代码块

try {
    $end$
} catch (Exception e) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    e.printStackTrace(pw);
    pw.flush();
    sw.flush();
    String strEx = sw.toString();
    if(null!=log){
        log.error("★★★★★★★★★★---"+Thread.currentThread().getStackTrace()[1].getMethodName()+"发送了异常:\n{}", strEx);
    }else{
        System.out.println("★★★★★★★★★★---"+Thread.currentThread().getStackTrace()[1].getMethodName()+"发送了异常:\n"+ strEx);
    }
}

2.1 syso 快捷输出

syso
System.out.println("★★★★★★---》"+$end$);

Guess you like

Origin blog.csdn.net/fen_dou_shao_nian/article/details/120537844