1、自定义异常

package com; public class ZeroException extends Exception { private static final long serialVersionUID = 1L; public ZeroException(){ super() ; } public ZeroException ( String string ) { super( string ) ; } }

2、异常捕捉

package com; public class Test { public static void main(String[] args) { Test test = new Test() ; try { test.fun( "" ) ; } catch (ZeroException e) { e.printStackTrace(); } } void fun( String string ) throws ZeroException { if( string == null ){ throw new ZeroException( "参数不能为null" ) ; } if( string == "" ) { throw new ZeroException( "参数不能为空" ) ; } } }

3、运行结果

com.ZeroException: 参数不能为空 at com.Test.fun(Test.java:22) at com.Test.main(Test.java:9)


更多相关文章

  1. android中AudioRecord采集音频的参数说明以及audioTrack的播放
  2. android 开发使用 kotlin 进行点击事件监听和界面跳转,直接传也方
  3. Android RectF类的构造函数参数说明
  4. android 广播传参数
  5. Android canvas clip 参数解释
  6. build.prop生成及参数解析
  7. Android -- android activity 各种布局方式以及相关参数
  8. 动态修改Android参数信息的方法绕过改机检测

随机推荐

  1. Android实现系统重新启动
  2. android:versionCode和android:versionNa
  3. Listview
  4. Android开发平台部署
  5. Android常用的技术点
  6. Android:用定时器刷 timer 新界面
  7. android环境部署(1.1)
  8. JS判断Android、iOS或浏览器的多种方法(
  9. Android(安卓)Studio Check for Update
  10. Android(安卓)各种布局技术-五大布局对象