I have an external application that writes to the general journal. When an error occurs it just has a basic description "error validating record" for example. I would also like to return the warning message as it is more detailed. Problem is i don't know how to catch the warning message in code and return it with the error back to my 3rd party app. So i ended up catching the error and then querying the sys exception table. But the issue seems to be a delay now. Which means it doesn't write the error/warning to the table until the aif service is completely out. So it will always return the last error instead of the current error. See code below. IF there is a better solution to get the warning returned let me know. i have looked around and nothing seemed to work.
catch (Exception::Error)
{
select maxOf(createdDateTime) from sysExceptionTable where sysExceptionTable.Exception==Exception::Warning && (sysExceptionTable.createdBy=='username' || sysExceptionTable.createdBy=='username');
select description from sysExceptionTable2 where sysExceptionTable2.Exception==Exception::Error && (sysExceptionTable2.createdBy=='username' || sysExceptionTable2.createdBy=='username') && sysExceptionTable2.CreatedDateTime==sysExceptionTable.createdDateTime;
errorMsg=sysExceptionTable2.Description;
select description from sysExceptionTable2 where sysExceptionTable2.Exception==Exception::Warning && (sysExceptionTable2.createdBy=='username' || sysExceptionTable2.createdBy=='username') && sysExceptionTable2.CreatedDateTime==sysExceptionTable.createdDateTime;
errorMsg=errorMsg + " " + sysExceptionTable2.Description;
throw Global::error(errorMsg);
}