My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

19 October 2010

X++ Code Snippet: handle all values in a conditional statement

by Patrik Luca 0 comments


This X++ Code Snippet describes how to handle all values in a switch statement or if else statement. If you want to avoid someone calls the function or method with a value which isn’t explicitly handled in your conditional statement, you can throw an error with the name of the function to the end user, making the end user aware of the fact that an unexpected value is used in the written code.

For a switch statement you add the default section as follows:

switch (_variable)
case value1:
some code;
case value2:
some code;
throw error(strFmt("@SYS23396",funcName()));

For an if else statement:

if (value1)
some code;
throw error(strFmt("@SYS23396",funcName()));

Comments 0 comments

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries


Recommended Books

Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Live Traffic Feed

Recent Visitors

Blog Archive

My Blog List


Guest Links