`

throw and throws

 
阅读更多

throw和throws关键字的区别


throw用来抛出一个异常,在方法体内。

syntax:throw 异常对象。

example:throw newArithmeticException("arith");

或者: ArithmeticException e = new ArithmeticException("arith");

throw e;

注意: throws后面不能跟语句,因为根本不会执行。那样会出现编译错误。

throws用来声明方法可能会抛出什么异常,在方法名后。

syntax:throws 异常类型1,异常类型2...异常类型n

http://java.chinaitlab.com/base/745197.html,关于异常处理机制很好的文章

分享到:
评论

相关推荐

    好用的phpExcel

    you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your...

    android 串口驱动

    public SerialPort(File device, int baudrate) throws SecurityException, IOException { /* Check access permission */ if (!device.canRead() || !device.canWrite()) { try { /* Missing read/...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Tabs Function Declarations and Definitions Function Calls Conditionals Loops and Switch Statements Pointer and Reference Expressions Boolean Expressions Return Values Variable and Array ...

    Servlet查询数据库案例--Query(java源码)

    // If anything goes wrong, log it, wrap the exception and re-throw it try { Class.forName(driverClassName); db = DriverManager.getConnection(url, username, password); } catch (Exception e) { ...

    LINQPad_Premium_5.36.03_Any_CPU 含破解

    LINQPad now identifies NuGet packages with duplicate extension attributes in Content_Types.xml, and automatically removes the duplicates so that the package loader will not throw an ...

    spring aop 实现源代码--xml and annotation(带lib包)

    Spring根据Adivce加入到业务流程的时机的不同,提供了四种不同的Advice:Before Advice、After Advice、Around Advice、Throw Advice。 1、Before Advice 顾名思义,Before Advice会在目标对象的方法执行之前被调用...

    带注释的Bootstrap.java

    throws Exception { //CatalinaProperties解析$CATALINA_HOME\conf\catalina.properties, //并将catalina.properties内的属性存为系统属性 //catalina.properties内common.loader="${catalina.base}/lib", ...

    File_实用案例_实现文件拷贝_FileCopy.java

    * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the ...

    RMI 的全套使用

    * 使用默认端口,默认服务器名称,服务路径构造函数 use the default port,server name and the url */ public RMIServer(Remote obj) { this.serverInterface = obj; } /* * 使用默认端口,服务路径构造...

    java sql注入l

    44 throw new IOException("您发送请求中的参数中含有非法字符"); 45 //String ip = req.getRemoteAddr(); 46 } else { 47 chain.doFilter(args0,args1); 48 } 49 } 50 51 //效验 52 protected ...

    编译原理龙书答案

    any string derived from the grammar can be considered to be a sequence consisting of 11, 1001 and 0, and not prefixed with 0. the sum of this string is: sum = Σn (21 + 20) * 2 n + Σm (23 + 20) * 2m ...

    把整数生成唯一字符串的PHP库.zip

     throw new RuntimeException('Missing BC Math or GMP extension.');  }字符串或串(String)是由数字、字母、下划线组成的一串字符。一般记为 s=“a1a2···an”(n>=0)。它是编程语言中表示文本的数据...

    java jdk实列宝典 光盘源代码

    throw和throws、try和catch;自定义异常类;使用finally;使用异常的技巧和原则; 7 IO输入输出流 获取文件的基本信息;列出指定目录下的文件,并可过滤文件;创建文件和目录;删除文件和目录;移动文件和目录; 复制...

    commons-fileupload-1.2.jar和commons-io-1.3.2.jar

    // text file, the second is unknown and is written to a file on // the server Iterator iter = fileItems.iterator(); // 正则匹配,过滤路径取文件名 String regExp = ".+\\\\(.+)$"; // 过滤掉的文件...

    springmybatis

    MyBatis 目录(?)[-] mybatis实战教程mybatis in action之一开发环境搭建 mybatis实战教程mybatis in action之二以接口的方式编程 mybatis实战教程mybatis in action之三实现数据的增删改查 mybatis实战教程mybatis ...

    二十三种设计模式【PDF版】

    主要是介绍各种格式流行的软件设计模式,对于程序员的进一步提升起推进作用,有时间可以随便翻翻~~ 23种设计模式汇集 如果你还不了解设计模式是什么的话? 那就先看设计模式引言 ! 学习 GoF 设计模式的重要性 ...

    超级有影响力霸气的Java面试题大全文档

    &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。 14、HashMap和Hashtable的区别。 HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空...

    java 面试题 总结

    &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。 11、HashMap和Hashtable的区别。 HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空...

    Java开发技术大全(500个源代码).

    throwsException.java 声明抛出异常 useMyException.java 使用自定义异常 第7章 示例描述:本章学习Java的输入和输出。 CopyFile.java 文件复制实例 dir.java 显示目录下的所有文件和目录 encrypt.java 文件...

    ssh(structs,spring,hibernate)框架中的上传下载

    8. …//getter and setter 9. }  特别需要注意的是:数据库表为Blob类型的字段在Tfile中的fileContent类型为byte[]。Tfile的Hibernate映射文件Tfile.hbm.xml放在Tfile .java类文件的相同目录下:  代码 2 领域...

Global site tag (gtag.js) - Google Analytics