web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to get Exception type outside Catch() ?

(0) ShareShare
ReportReport
Posted on by 552
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
 
 
 
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    9,023 Super User 2025 Season 2 on at
    How to get Exception type outside Catch() ?
     
    You can try this code  :
     
    try
    {
    // Your logic
    }
    catch (Exception::CLRError)
    {
       ex = ClrInterop::getLastException();
      if (ex != null)
      {
        ex = ex.get_InnerException();
       if (ex != null)
      {
        error(ex.ToString());
       }
      }
    }
     
     
    Regards,
    Waed Ayyad
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
  • Verified answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    How to get Exception type outside Catch() ?
    Hi Ken,

    You need to catch the error for it to appear. This is how i prefer to catch exceptions
     
    System.Exception  ex;
    
    try
    {   
    }
    catch(ex)
    {
       error(ex.message);
      this.errorProcedure(); }

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 724 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 619 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans