Skip to main content

I am using a try - catch and trapping an error.  When I get the error, I want to write it to the trace log.  I am able to write to the log.  There is a property in the System.Exception called “InnerMessages” that is an array of the actual errors that caused the exception.  

Here is a print screen of the InnerMessages that shows the details I want to write to the log:

 

I write to the log with PXTrace.WriteError(ex);

This is the only thing that shows in the Trace screen.  It just shows the basic message and the place in my code where the error occurred.

My thought is that I could cycle through the InnerMessages array and write it to the trace log so if my customer has an error, I can actually know what it is.

Does anyone know how I can access the InnerMessages property?  I cannot find any way to do it.

@Django I know why I cannot access InnerMessages.  The actual exception thrown is an Acumatica exception, not a System.Exception.  In my printscreen above, I noticed it had some Acumatica lingo in it so I did this test to see what the exception type is.

When I try to get the info for the exception, in my code, “e.” intellisense only brings up the System.Exception information.  Do I need to “cast” the exception to a PX exception somehow?  

This is more of a C# issue.  I’m a VB developer by trade, so I’m not very sharp with c#.😉

I think I am on my way to getting this.

This code works for me.  I’m going to make a class so I can reuse this in other places.

            catch (Exception e)
            {
                if(e.GetType().FullName == "PX.Data.PXOuterException")
                {
                    StringBuilder sb = new StringBuilder();
                    PXOuterException pX = (PXOuterException)e;

                    sb.Append(e.Message + Environment.NewLine);
                    foreach (string item in pX.InnerMessages)
                    {
                        sb.Append(item + Environment.NewLine);
                    }

                    PXTrace.WriteError(sb.ToString());
                }
                ex = e;
            }
Isn’t it pretty!

 


I’m thinking that the answers on this SO question should be able to help

https://stackoverflow.com/a/35084416/9542263

It looks like

e.InnerMessages.ToString() would give you something to work with.


Reply