• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

OCA Java SE 8 Programmer I Certification Guide by Mala Gupta, Twist in Tale 7.3 on page 502

 
Ranch Hand
Posts: 61
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why I don't get a StackOverflowError with the code:



The method myMethod() will be called recursively! On my Mac I get the result:

0
1



But why I don't get a StackOverflowError?? In the book is said, that I will receive a Java.lang.StackOverflowError?!
 
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Gualeni wrote:Hi,

Why I don't get a StackOverflowError with the code:

Because you are catching the stackoverflowerror error in the catch block and using the for loop to display the values

 
Mike Gualeni
Ranch Hand
Posts: 61
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer. I understand what you mean. But the problem is in the book there are theses solutions:

a    0


b    java.lang.StackOverflowError


c     0
     1

d     0
     1
     2
     3
     java.lang.StackOverflowError



and in the explanation to this question:

Purpose: To determine whether exception-handling code for errors will execute.

Answer:   b

Explanation: We know that typically errors shouldn't be handled programmatically
and that they should be left for the JVM to take care of. Also, you can't be sure that
error-handling code for all the errors will execute. For example, error-handling code
for StackOverflowError may execute but (as the name suggests) may not execute for
VirtualMachineError.

Is this an error in the book?  I don't know. From the above explanation StackOverflowError, the answer to the purpose is: exception-handling code for errors will execute (for StackOverflowError surely). In this case, why she choose b as answer? Who knows?
 
Marshal
Posts: 69809
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check very carefully that you have copied everything exactly. I didn't find that question in the errata. The output 0 1 is correct.
 
Mike Gualeni
Ranch Hand
Posts: 61
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I reentered the whole code and I checked it several times. The code in my IDE is the same as in the book.

Nevertheless the answer in the book is b = java.lang.StackOverflowError. And my output is 0 1!
 
Campbell Ritchie
Marshal
Posts: 69809
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pease log in to the Manning site and report that as a potential erratum.
 
Mike Gualeni
Ranch Hand
Posts: 61
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already made!
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic