Avatar of gudii9
gudii9
Flag for United States of America

asked on 

exception return

class ExceptionReturn
{
public static void main(String[] args)
{
System.out.println(m1());
}
public static getName(){
try
{
System.out.println(10/0);
return 1;
}
catch(ArithmeticException e)
{
return 2;
}
finally{
return 3;
}
}}

Open in new window


i wonder why i got 3 as output not 1,2

class ExceptionReturn2 {
	
	public static void main(String[] args) {

		try {
			System.out.println("try");
			//System.exit(0);
			return;
			//System.exit(0);
		} catch (ArithmeticException e) {
			System.out.println("catch");
		} finally {
			System.out.println("finally");
		}
	}
}

Open in new window


how finally overriding return

System.exit(0); cannot be given after return?

please advise
Java EEJava

Avatar of undefined
Last Comment
jglete

8/22/2022 - Mon