Java Exception Handling || finally block vs return statement || by Durga Sir

Java Exception Handling || finally block vs return statement || by Durga Sir

Durga Software Solutions

5 лет назад

8,800 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@shaiknafeezahmed9139
@shaiknafeezahmed9139 - 07.08.2021 20:04

finally{
System.out.println("THANK YOU SIR")
}

Ответить
@theexplorer1127
@theexplorer1127 - 16.02.2019 07:59

Sir can u please explain the flow when return statement throws an exception ... i.e
import java.util.Scanner;
class Test
{
public static int m1()
{
try
{
System.out.print("try");
return 10/0;
}
catch (ArithmeticException e)
{
System.out.print("\ncatch");
return 88;
}
finally
{
System.out.print("\nfinally");
return 99;
}
//return 0;
}
public final strictfp synchronized static void main(String... vinay)
{
System.out.print(m1());
}
}


output :
try
catch
finally
99


it seems to be like only after execution of try blocks return statement finally block got executed.
if after executing finally block try blocks return statement executed then output will be as follows:

try
finally
catch
99


can u please elaborate this?

Ответить
@kuldeepkushwaha1115
@kuldeepkushwaha1115 - 11.02.2019 19:10

nice tutorial

Ответить
@punks0325
@punks0325 - 11.02.2019 17:11

Thanku sir...

Ответить