try-catch-finally in which part can be omitted?

Copyright: Reprinted please note the name of the source https://blog.csdn.net/meism5/article/details/90414167

try-catch-finally in which part can be omitted?

catch finally block can be omitted and wherein a.

package constxiong.interview;

public class TestOmitTryCatchFinally {

	public static void main(String[] args) {
		omitFinally();
		omitCatch();
	}
	
	/**
	 * 省略finally 语句块
	 */
	public static void omitFinally() {
		try {
			int i = 0;
			i += 1;
			System.out.println(i);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 省略 catch 语句块
	 */
	public static void omitCatch() {
		int i = 0;
		try {
			i += 1;
		} finally {
			i = 10;
		}
		System.out.println(i);
	}
}

 

 

More columns:

Guess you like

Origin blog.csdn.net/meism5/article/details/90414167