{"id":99,"date":"2019-09-25T13:26:29","date_gmt":"2019-09-25T16:26:29","guid":{"rendered":"https:\/\/pedrotornich.com\/a\/?p=99"},"modified":"2019-09-25T13:26:31","modified_gmt":"2019-09-25T16:26:31","slug":"get-call-stack","status":"publish","type":"post","link":"https:\/\/pedrotornich.com\/a\/2019\/09\/25\/get-call-stack\/","title":{"rendered":"Get call stack"},"content":{"rendered":"\n<p>Hi folks,<\/p>\n\n\n\n<p>Sometimes you want to debug a process in AX2012 but it&#8217;s running in batch and you don&#8217;t want to setup up batch debugging.<\/p>\n\n\n\n<p>In this case you can add a throw to the code to check the value of a variable, but even if you do this you won&#8217;t be able to know what was the caller.<\/p>\n\n\n\n<p>So, here is a sample code to get the current call stack:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp line-numbers\">    System.Diagnostics.StackTrace myStackTrace = new System.Diagnostics.StackTrace(true);\n    System.Exception ex;\n    str callStack;\n\n    if (xSession::isCLRSession())\n    {\n        try\n        {\n            callStack = myStackTrace.ToString();\n        }\n        catch\n        {\n            ex = ClrInterop::getLastException();\n            if (ex != null)\n            {\n                ex = ex.get_InnerException();\n                if (ex != null)\n                {\n                    info(ex.ToString());\n                }\n            }\n        }\n    }\n    else\n    {\n        callStack = con2Str(xSession::xppCallStack());\n    }\n\n    throw info(callStack);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi folks, Sometimes you want to debug a process in AX2012 but it&#8217;s running in batch and you don&#8217;t want to setup up batch debugging. In this case you can add a throw to the code to check the value of a variable, but even if you do this you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-ax2012"],"_links":{"self":[{"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":1,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":100,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/posts\/99\/revisions\/100"}],"wp:attachment":[{"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pedrotornich.com\/a\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}