zoukankan      html  css  js  c++  java
  • springframework中Assert的用法

    使用assert的好处就是比较简洁,不用加try catch就可以附加一些预期的提示信息,方便定位问题

    1 import org.springframework.util.Assert;
    2 
    3 public class Demo {
    4     public static void main(String[] args) {
    5         String location = null;
    6         Assert.notNull(location, "Location must not be null");
    7         System.out.println("location = [" + location + "]");
    8     }
    9 }
    Demo

    Output:

    1 Exception in thread "main" java.lang.IllegalArgumentException: Location must not be null
    2     at org.springframework.util.Assert.notNull(Assert.java:115)
    3     at Demo.main(Demo.java:9)
    4     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    5     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    6     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    7     at java.lang.reflect.Method.invoke(Method.java:498)
    8     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
    View Code
  • 相关阅读:
    CSS实现返回网页顶部
    jQuery实现小火箭动态返回顶部代码
    Linux目录结构介绍
    Linux常用命令及技巧
    Linux文件系统
    Linux特性
    numpy中基础函数
    restful规范
    堆栈
    三次握手与四次挥手
  • 原文地址:https://www.cnblogs.com/TomJay/p/9670670.html
Copyright © 2011-2022 走看看