Skip to main content
Dynamics 365 Community / Forums / Finance forum / How to get Exception t...
Answered

How to get Exception type outside Catch() ?

editSubscribe (0) ShareShare
ReportReport
Posted on by 353
Hi,
 
In my code currently the Try and Catch() does not specifically put the Catch in several Exception type,  If I'm looking at other code or blogs, usually it would be something like this :
 
str error;try    {        // ...    }    catch (Exception::Error)    {        enumerator = SysInfologEnumerator::newData(infolog.cut());        while (enumerator.moveNext())        {            strc = new SysInfologMessageStruct(enumerator.currentMessage());            exception = enumerator.currentException();            error = strfmt('%1 %2', error, strc.message());        }
 
But currently, I only put like this :
 
try
    {
        ......
     }
catch
     {
          this.errorProcedure();
     }
 
 
And in my errorProcedure, I'm grabbing the error in infolog which then insert the error log into my log table, Something like this :
 
public void errorProcedure()
{
         container   infoData = infolog.infologData();
        Str1260     errorTxt;
       
         for (int i = 1; i <= conLen(infoData); i++)
        {
            container internalInfoData = conPeek(infoData, i);
            if (errorTxt == //)
            {
                errorTxt =  conPeek(internalInfoData, 2);
            }
            else
            {
                errorTxt += /;/ + conPeek(internalInfoData, 2);
            }
        }
        // insert into log table
}
         
Issue is, turns out it doesn't catch some error. For example like inside the Try block, there is incident of calculation with divide by zero. This will result the program exit to Catch block and run my errorProcedure(), but there is no infolog and when debug I found that there is an exception ->
The above screenshot is when I debug in the middle of that errorProcedure steps, so I'm thinking, actually the exception still recognize and there is the message which quite clear, only it doesn't /belong/ to the infolog object.
 
How to actually handle this ? Can we still grab the Exception if we put like this ? Can I also grab the Exception and the message /Attempted to divide by zero/ then concat it to my errorTxt string ?
 
Please help.
 
Thanks