Hi folks,
I got some development question, especially to get the correct error message that I would like to rectify.
I'm creating a class that have this flow in that same one class:
internal final class ThisClass() { static void main(Args _args) { try { ThisClass thisClass = new ThisClass(); if (thisClass.transfer()) { } } catch (Exception::Error) { error("Critical error has been thrown and the process is stopped."); } } public boolean transfer() { boolean success = false; try { if (this.validateData()) { ttsbegin; if ( this.createTransData()) success = true; ttscommit; } } catch (Exception::Error) { ttsabort; container infoData = infolog.infologData(); Str1260 errorTxt; for (int i=1;i<= conLen(infoData);i ) { container internalInfoData = conPeek(infoData,i); if (conPeek(internalInfoData,1) == Exception::Error || conPeek(internalInfoData,1) == Exception::Warning) { if (errorTxt == "") { errorTxt = conPeek(internalInfoData,2); } else { errorTxt = errorTxt ";" conPeek(internalInfoData,2); } } } } return success; } public boolean validateData() { if (myTable.field == "") { success = false; throw error(strFmt("@SYS136411", fieldId2PName(tableNum(MyTable), fieldNum(MyTable, field)))); } return success; } }
To make more simple explanation, the path should be : Main() -> transfer() -> validateData()
My question is when in that validation method which will check my field, if it is empty then it will throwError then return false. Then as per my understanding it will going to Catch in the caller method, which is also correct at this point, it is going to that catch(Exception:Error)
However If I look at the debug, I wonder why in that infologData() has already contain several message which I thought it will retrieve after this 1st throw error, like below:
As we can see, the infolog already contain 5 rows container, which no 3 is the message from Main(), also in its 1st row container, it is a system message saying cannot edit record which I believe because there is some statement of "update recordset" which I put after it is ran that method validateData(), which I thought since it is failed validation, it will not even go to update_recordset (but this is my thought only)
I'm wondering whether this is the correct way of error trap, and secondly, if I want to get the last row of the infolog container only which is the one I need to tell my user in some Log table, where is the correct place to insert the message and how to retrieve only the last (no 4) infolog container.
Thanks,
You're still claiming that 'throw error' returns false; but that's a nonsense. Neither the statement nor the method where you call it returns true or false. Instead, an exception is thrown. Then you're right in expecting that when an exception is thrown, it may be caught by a catch statement. It wouldn't be true if a method really returned false. You seem to be confirming that the exception is indeed thrown and caught, therefore it all works correctly (although not according to your description). If that's true, then there is problem with throw/catch and this whole discussion is irrelevant to your actual problem.
You code reads everything currently in infolog (which may include old unrelated messages), not just what was added validateData(). You could fix that by checking the infolog line number (infologLine()) before running your process and reading messages just from this line.
Ok, I think I got everyone lost at my explanation of this word ""when I hit error in my validation, then it will hit throwError".
Let me try to rephrase it (I changed the original and copied back here as well) -->
My issue is when in that validation method which will check my field, if it is empty then it will throwError then return false. Then as per my understanding it will going to Catch in the caller method, which is also correct at this point, it is going to that catch(Exception:Error)
Hope my assumption on where it is got lost is correct. So, it is not about my code has error, but when the program run, and as the flow goes, it will goes to that method validateData(), and if it is true that my field is empty, then it will throw Error.
And the question is why the infolog contain that 5 rows with all those messages ?
My intention is to get only the message from the validateData(), and I'm planning to insert this specific message into some log table. So I want to know where is the best place to put that insert statement.
Thanks,
I'm sorry, but I can't address your problem, because I don't understand your description of the problem. Consider explaining it once more.
Hi,
Yes, that's why I'm asking here to know, what or how to make sense / the correct way. Which one I should correct it ?
Thanks.
If you mean the throw statement when talking about throwError, the sentence still doesn't make sense. The throw statement doesn't return false - it throws an exception.
Hi Martin,
There is "throw error" in method validateData(). When checking the field in my table empty or not, when it is empty, execute Throw error.
Thanks,
I got lost already at the beginning of your problem description. You said "when I hit error in my validation, then it will hit throwError which is expected then return false", but I see no throwError method in code that you shared with us.
André Arnaud de Cal...
292,111
Super User 2025 Season 1
Martin Dráb
230,934
Most Valuable Professional
nmaenpaa
101,156