课堂异常处理练习

课堂异常处理练习

package test;

public class TestException {
    
    
	
	
	public static void main(String args[]) {
    
    
		int s1=10,s2=0,s3=100;

		try {
    
    	
			div();			
			if(s3==100)throw new Exception("主动抛出异常");				
			s3=s3+s1;			
		}
		
		catch(RuntimeException e) {
    
    
		   System.out.println(e.getMessage());	
		   //e.printStackTrace();	
		}
		
		catch(Exception e) {
    
    
			   System.out.println(e.getMessage());	
			   //e.printStackTrace();	
		}
		
		
		finally {
    
    
			System.out.println(s3);			
		}
		
		System.out.println("2222222222222222");		
	}
	
	
	public static void div() throws Exception {
    
    
		
	 
		int s1=10,s2=0,s3=100;
		s3=s1/s2;
 
	}
	
	
}

猜你喜欢

转载自blog.csdn.net/Climbman/article/details/130901212
今日推荐