A developer has the following code:try {List nameList;Account - ProProfs Discuss
Topics
Products
Follow Us:

A developer has the following code:try {List nameList;Account a;String s = a.Name;nameList.add(s);} catch (ListException le ) {System.debug(' List Exception ');} catch (NullPointerException npe) {System.debug(' NullPointer Exception ');} catch (Exception e) {System.debug(' Generic Exception ');} What message will be logged?



A. List Exception
B. NullPointer Exception
C. Generic Exception
D. No message is logged

This question is part of Salesforce Platform Developer 1
Asked by Wyatt Williams, Last updated: Jan 14, 2020

+ Answer
Request

3 Answers

YoyoSuccess

YoyoSuccess

Answered Jul 17, 2017

I executed the following and got No Exception.

try {
List nameList = new List();
Account a = new Account(Name = 'TestDevAccount');
String s = a.Name;
nameList.add(s);
System.debug(' No Exception ');
}
catch (ListException le ) {System.debug(' List Exception ');}
catch (NullPointerException npe) {System.debug(' NullPointer Exception ');}
catch (Exception e) {System.debug(' Generic Exception ');}

otherwise I just get the anonymous error:

unexpected token: 'List'

1
 

fcaetano

Fcaetano

Answered Nov 13, 2017

Well I think the first line of the code should be "List < string > namelist;" That being said, you will get a NullPointer Exception on line "String s = a.Name;", because you're trying to retrieve the Name field of an account record that's null.

 

John Smith

John Smith

Answered Apr 26, 2017

NullPointer Exception

####
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.