Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

roundup question errors  RSS feed

 
Murat Gungor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Answer to the question #127 says that if(b=true) is a valid statement. It goes on saying that b will be assigned to the value true...
Answer to the question #132 says that if finally clause is executed, remaining statments in the current method will be skipped...Well, only the remaining statements in the try block would be skipped, not the whole method...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
For #127, the text is correct as is. Try compiling and running it - you'll see.
For #132, the text is: "If an exception is not caught, the finally block will run and the rest of the method is skipped." This is also correct. Perhaps it is not clear that "if an exception is not caught" means "if there is an exception thrown which is not caught" rather than "if no exception is caught(possibly because none was thrown)". In the former case - if an exception is thrown and not caught - then the only thing in the method that will still execute is the finally clause. Again, try it.
 
Murat Gungor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks for the reply Jim,
On the first one, I didn't realize that the if statement was evaluating the outcome of the expression, rather than operating on an invalid comparison - which would be caught by the compiler...
On the second one, I didn't assume that an exception was thrown - hence your suggestion of re-wording the question...
Regards, :roll:
 
Murat Gungor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
In the former case - if an exception is thrown and not caught - then the only thing in the method that will still execute is the finally clause. Again, try it.

If the try block where the exception is thrown is wrapped with another try block, then the rest of the code in the method after the outer try block will not be skipped...
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!