I am developing a tool to read the data from a file and store in a linked list. I access the linked list and write the data into another file depending on some conditions.
The base structures needed for this operation are:
typedef struct ElemNode
CString szID; WORD wLength; ValueType eType; CString szValue; ElemNode *pNextElem; }ElemNode;
typedef struct ItemNode
CString szID; WORD wLength; ValueType eType; CString szValue; ElemNode *pElemList; ItemNode *pNextItem; }ItemNode;
The Linked list structure after reading the data is something like :
ItemNode -> ElemNode -> ElemNode -> ElemNode
ItemNode -> NULL
ItemNode -> ElemNode -> ElemNode -> ElemNode ... (conatins 13 ElemNodes)
ItemNode -> ElemNode -> ... (contains 16 ElemNodes).
I need to access the szValue field of the 3rd ElemNode (shown in bold)in 1st ItemNode structure. I directly use the following statement.
ItemNode *pFirstItem; CString strTempString = pFirstItem->pElemList->pNextElem->pNextElem->szValue
If one of the ElemNode is missing, then this statement will cause the app to crash. I know of using UserException and throwing them. But the problem is, I can't go putting my own code to check for the NULL cases and throw the UserException.
Is there any way I can avoid the crash by throwing an exception? In other words, what is the exception thrown by the system in such cases?
I am using MFC and developing this tool in Visual-Studio 2005.
If there is any project related settings that is needed, please tell me.