0

I am building an angular web application and I am wanting to send any javascript exceptions and callstacks from the client to the server for logging. In chrome and firefox I am able to get the callstack by looking at the exception.stack property, but this value is not available when using IE. Here is a code example from my angular controller:

function LogTestController($scope) {
    $scope.TestError = function () {
        callError1();
    }

    function callError1() {
        callError2();
    }

    function callError2() {
        var x = y;
    }
};

And here is the exception.stack from chrome:

"ReferenceError: y is not defined
at callError2 (http://localhost:85/App/Offer/OfferController.js:16:17)
at callError1 (http://localhost:85/App/Offer/OfferController.js:12:9)
at Scope.LogTestController.$scope.TestError (http://localhost:85/App/Offer/OfferController.js:8:9)
at $parseFunctionCall (http://localhost:85/Scripts/angular.js:12345:18)
at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:85/Scripts/angular.js:21435:17)
at Scope.$get.Scope.$eval (http://localhost:85/Scripts/angular.js:14401:28)
at Scope.$get.Scope.$apply (http://localhost:85/Scripts/angular.js:14500:23)
at HTMLButtonElement.<anonymous> (http://localhost:85/Scripts/angular.js:21440:23)
at HTMLButtonElement.jQuery.event.dispatch (http://localhost:85/Scripts/jquery-1.9.1.js:3074:9)
at HTMLButtonElement.jQuery.event.add.elemData.handle (http://localhost:85/Scripts/jquery-1.9.1.js:2750:46)" 

Which is very helpful in debugging. But IE does not have the extension.stack property when the error occurs inside of the angular controller.

However if I force the same error in IE when it is not inside an angular controller then there is a value for exception.stack. Here is an example of that code:

    <script type="text/javascript">
        try {
            first();
        } catch (exception) {
            var trace = exception.stack;
        };

        function first() {
            second();
        };

        function second() {
            var x = y;
        }
    </script>

In IE the exception.trace is as follows:

"ReferenceError: 'y' is undefined
   at second (http://localhost:85/App/logtest.html:20:13)
   at first (http://localhost:85/App/logtest.html:16:13)
   at Global code (http://localhost:85/App/logtest.html:10:13)"

I have also tried to use stacktrace.js to get the callstack from IE, but this library is reliant on the exception.stack value to be present.

Could somebody please help me understand why this is acting differently when inside an angular controller and how to get the stack trace from IE inside the angular controller?

Thanks

that guy
  • 1
  • 1
  • what happens if you use simply `console.error( exception )` ? `console.error` has a specific behavior which is safer than a simple log of the stack. – floribon Mar 12 '15 at 21:10
  • `console.error(exception)` writes out the exception message only and not the stacktrace. The stacktrace has much more valuable information which helps with debugging. – that guy Mar 12 '15 at 21:37
  • I don't know about IE, but in Chrome `console.error` should log the full stack of the error. If it does not, it means the error in not a real one (i.e. an instance of `Error`, as in `new Error('message')`) – floribon Mar 12 '15 at 21:48

0 Answers0