aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL: null-friendly vs exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL: null-friendly vs exceptions" Watch "EL: null-friendly vs exceptions" New topic
Author

EL: null-friendly vs exceptions

Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93
In HFSJ book EL chapter, it says EL is null-friendly and handles null values gracefully.

For example, there is an attribute named "bar", which does not have a property or key named "foo".
${bar[foo]} is null, since foo is not a property or a key of bar, but EL handles it gracefully. It just shows nothing printed out.

My understanding is, behind the scene, there is an exception thrown, am I right?
By the way, I don't have my environments set up yet. I usully do it after I go throught the book, then I'd try on those cases that I am not sure of. I just need a quick confirmation from those knowledgables whether I am right or not. Or I'll wait to find out myself after I go through the book.


"There are no dumb questions" quoted from HFSJ. "To err is human; to forgive is divine"
OCPJP 6, OCEJWCD 6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Joe Allen wrote:My understanding is, behind the scene, there is an exception thrown, am I right?

Unlikely. It's much more likely that the EL interpreter will do null checks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93
Hi Bear, thanks for answering my question again.

The reason I thought there was an exception thrown behind the scene is because in doing item 17 (pg 437) of HFSJ chapter 8 mock exam, I didn't get one of the two correct answers right. I thought null-friendly means no exceptions.

17) Which about EL access operators are true?
C. If the .(dot) operator is used to access a bean property but the property doesn't exist, then a runtime exception is thrown. (one of the two correct answers)

But again, it could be an errdata too. That is why I posted the question.
Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93
I just came upon the answer, as I was reading HFSJ. It says, in p457(about <c:set target= property= value= >), "If the "target" expression is a bean, but the bean does not have a property that matches "property", the Container throws an exceiption. Remember that the EL expression ${bean.notAProperty} will also throw an exception.".

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL: null-friendly vs exceptions