Forum Discussion

RUDOLF_BOTHMA's avatar
RUDOLF_BOTHMA
Community Hero
6 years ago
Solved

call stack on application exception not returning full stack

Hi all,   I'm trying to improve the error handling of my scripting.  Sometimes I have a try/catch in my code to handle some application exceptions e.g. trying to edit a readonly file   Curren...
  • tristaanogre's avatar
    6 years ago

    That's because the Call Stack is recorded at hte moment that "Log.Error" is called.... and at that point, the only "stack" that is there is the initial LogError call and LogException call.  If you want to see the stack that you are requesting, you should change your code to this so that the Log.Error is at the very bottom of your stack.

    function LogError()
    {
      try
      {
        LogErrorStack1();
      }
      catch(e)
      {
        //Handle Exception
      }
    }
    
    function LogErrorStack1()
    {
      try   
      {
        LogErrorStack2();
      }
      catch(e)
      {
        throw e;
      }
    }
    
    function LogErrorStack2()
    {
      try
      {
        throw("test exception");
      }
      catch(e)
      {
        LogException(e,"Perhaps you should try that again");
      }
    }
    
    function LogException(exception, additionalInformation)
    {
      Log.Error("An application exception was encountered: \n" + exception,additionalInformation);
      //More work for different exceptions
    }