Files
freeCodeCamp/guide/chinese/java/throws-keyword/index.md
2018-10-16 21:32:40 +05:30

32 lines
707 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Throws
localeTitle: 抛出
---
## 投
Java throws关键字用于声明异常。它向程序员提供了一个信息即可能会出现异常因此程序员最好提供异常处理代码以便保持正常的流程。
**_例_**
```java
import java.io.IOException;
class Testthrows1{
void m()throws IOException{
throw new IOException("device error");//checked exception
}
void n()throws IOException{
m();
}
void p(){
try{
n();
}catch(Exception e){System.out.println("exception handled");}
}
public static void main(String args[]){
Testthrows1 obj=new Testthrows1();
obj.p();
System.out.println("normal flow...");
}
}
```