+ 1

Not able to catch StackoverflowException

The below code attempts to dividebyzero causing DivideByZeroException and it is caught in the catch block static void main() { try { console.write(5/0); } catch (Exception ex) { console.write("abc"); } Nw the code below calls the main() method recursively causing StackOverflowException,but it is not caught in the catch block static void main() { try { main(); } catch (Exception ex) { console.write("abc"); } } output is supposed to be "abc",but it throws the exception. Cn someone plz explain abt dis behavior

4th Dec 2017, 5:16 PM
Venkat Subramanian
Venkat Subramanian - avatar
2 Respuestas
+ 4
In order to be able to catch a exception main must be running. If the exception kills main you won't be able to catch the exception.
4th Dec 2017, 7:09 PM
sneeze
sneeze - avatar
+ 2
Cus you do the recursive without bool or throwed exception handle at all 😑
4th Dec 2017, 5:26 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar