⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 throwingexceptions.java

📁 java程序设计语言源代码
💻 JAVA
字号:
//Example 4 of Chapter 4

import java.io.*;
public class ThrowingExceptions
{
	public static void main( String args[] )
	{
		try {
			throw1();
		}
		catch ( EOFException eofe )
		{
			System.err.println( eofe.getMessage() + "\n" );
		}
		catch ( IOException ioe )
		{
			System.err.println( ioe.getMessage() + "\n" );
		}
		catch ( Exception e )
		{
			System.err.println( e.getMessage() + "\n" );
			e.printStackTrace();
		}
	}
	
	public static void throw1() throws Exception
	{
		throw2();
	}
	
	public static void throw2() throws Exception
	{
		try{
			System.out.println( "方法二" );
			throw new Exception( "在方法二中抛出" );
		}
		catch(RuntimeException re)
		{
			System.err.println( "在方法二的捕获中抛出" );
		}
		finally{
			System.err.println( "finally总是执行的" );
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -