Single Choice Easy

QYou need to validate the date and throw an error if the date entered is null or greater than current system date. Which of X++ statements should you use?

ID: #9409 Exception Handling in D365 F&O X++ 138 views
Question Info
#9409Q ID
EasyDifficulty
Exception Handling in D365 F&O X++Topic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A
    a)	If(InputDate != datenull()){ Throw error(“Wrong selection of date”);}Else If(inputDate > systemDateGet()){Throw error(“Wrong selection of date”);}
  • B
    b)	If(InputDate == datenull() || inputDate > systemDateGet()){      Throw error(“Wrong selection of date”);}
  • C
    c)	If(InputDate != datenull()){    Throw error(“Wrong selection of date”);    If(inputDate > systemDateGet())    {         Throw error(“Wrong selection of date”);    }}
  • D
    d)	If(InputDate != datenull()){   Throw error(“Wrong selection of date”);}If(inputDate > systemDateGet()){  Throw error(“Wrong selection of date”);}
Correct Answer

Explanation

Justification:

  1. This statement is incorrect in the initial comparison. It states that if the input date is not null (that is, it contains a value), then throw an error. This does not meet the requirement, which states to throw an error if the input date is in fact null.
  2. This statement correctly performs the comparison against the input date. The first comparison checks to see if the input date is equal to null, or if it is after today’s date. If either of these conditions is met, the throw error is then executed.
  3. This statement is incorrect in the initial comparison. It states that if the input date is not null (i.e. it contains a value), then throw an error. This does not meet the requirement, which states to throw an error if the input date is in fact null.
  4. This statement is incorrect in the initial comparison. It states that if the input date is not null (that is, it contains a value), then throw an error. This does not meet the requirement, which states to throw an error if the input date is in fact null.

 

Related Lesson: Code Statements

Share This Question

Challenge a friend or share with your study group.