Trying to write details of an exception to the Trace log

  • 3 April 2023
  • 2 replies

Userlevel 7
Badge +3

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.


Best answer by Joe Schmucker 3 April 2023, 20:10

View original

2 replies

Userlevel 7
Badge +3

@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);

                ex = e;
Isn’t it pretty!


Userlevel 7
Badge +5

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

It looks like

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved