+ 1

defining int type before try_catch

in this below code: int result=0; int num1 = 8; int num2 = 4; try { result = num1 / num2; } catch (DivideByZeroException e) { Console.WriteLine("Error"); } finally { Console.WriteLine(result); } must the int result be defined by 0 (not declared) before entering try_catch. isnt it just enough to be declared and defined later in try?

24th Mar 2017, 3:59 PM
Amir Hossein Karimi
Amir Hossein Karimi - avatar
3 Antworten
+ 6
yup I think so
24th Mar 2017, 4:35 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 1
me too, so tried my desired code and it gave me error 😐
24th Mar 2017, 4:59 PM
Amir Hossein Karimi
Amir Hossein Karimi - avatar