• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mala Gupta's OCA book question

 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The publisher has posted an errata to this book (at Errata ). One of the corrections to the book (at Page 390, line #1) reads as below:
- None of the regular try,catch and finally blocks can exist independently.

My question is "why was the word regular introduced in the errata" ? And what is the meaning of a regular try/catch block ? Can a try block exist by itself without finally block ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N Sam wrote:My question is "why was the word regular introduced in the errata" ?

I'm not the author, but I assume the word "regular" is introduced to differentiate between the "regular" try (the one you have always used to handle exceptions) and the new try-with-resources (introduced in Java 7)

N Sam wrote:And what is the meaning of a regular try/catch block ? Can a try block exist by itself without finally block ?

A try-block can never exist independently! You always need 1 (or more) catch-block(s) and/or 1 finally-block. So these are all valid code snippets:
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With new Java 7 , try-with-resources syntax, try block can appear alone without any catch and final block
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Agarwal wrote:With new Java 7 , try-with-resources syntax, try block can appear alone without any catch and final block

That's exactly the reason why "regular" was added in the errata. And try-with-resources is not covered in the OCAJP7 exam (it is in the follow-up certification, OCPJP7)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic