try
{
code; //将自己的代码放在其中;
} catch(e) //如果上面的代码有错误,这里就捕获
{
alert(e.number); //获得错误信息
}
import java.io.*;//调用io包
public class SimpleCharInOut
{
public static void main(String args[])
{
char ch=' ';//定义个字符ch初始为‘ '
System.out.println(" Enter a character please");//在屏幕上输出Enter a character please
try {//你要监视的程式码放在 try 区块里即可。在 try 区块之后紧接著在 catch 子句里指定你希望捕捉的例外型态
ch=(char)System.in.read();//将从键盘输入的字符赋给ch
}
catch(IOException e) //如果上面的代码有错误,这里就捕获
{ } ;//错误后不进行操作
System.out.println("You're entered character:" + ch);// 在屏幕上输出You're entered character:
//和ch的值
}
}
InputStream is;
try{
is=openInputStream();
// do something
}catch(IOException e){
e.printStaceTrace(e);
}finally{
try{
is.close();
}catch(IOException e ){
}
}
InputStream is;
OutputStream os ;
try{
is=openInputStream();
// do something
}catch(IOException e){
e.printStaceTrace(e);
}finally{
try{
if (is != null ) is.close();
if (os != null ) os.close();
}catch(IOException e ){
}
}
try(
InputStream is = openInputStream();
OutputStream os = openOutStream();
){
// do something
}catch(IOException e){
e.printStaceTrace(e);
}
try(
InputStream is = openInputStream();
OutputStream os = openOutStream();
){
// do something
}catch(IOException | XMLParseException | XPathException e){
e.printStaceTrace(e);
}
// 虽然这里用Exception匹配抛出的IOException,到编译器知道实际上抛给上层的异常是IOException
public void doIO() throws IOException {
try{
throw new IOException();
}catch(Exception e){
throw e;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有