0

I tried to control whole JavaScript application exceptions through a common method written but can't get any exact solution for the problem. I tried below code but sometimes it not worked

<script type="text/javascript">

            window.onerror = function () {
               alert("An error occurred.");
            }

      </script>

The same can be achieved in angular using below method :

$provide.decorator('$exceptionHandler', function ($delegate) {
        return function (exception, cause) {
            $delegate(exception, cause);
            var initInjector = angular.injector(['ng']);
            var $http = initInjector.get('$http');

            $http({
              method: 'POST',
              url: '/api/common/send_email',
              data: {message: new Date() +': '+ exception.stack},
              headers: {
                  'Content-Type': 'application/json;charset=utf-8'
              }
            }).then(function successCallback(response) {

              }, function errorCallback(response) {

              });
        };
    });

Can anyone please help me with a similar method in pure JavaScript or Jquery to handle complete application exceptions through a single method.

Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28
Rajendra Khabiya
  • 1,990
  • 2
  • 22
  • 39

1 Answers1

0

just don't use comments, should be like this

 <script type="text/javascript">
    window.onerror = function myErrHandler(errorMsg, url, lineNumber) {
        alert("Error: " + errorMsg);
        return false;
    }
</script>
justtry
  • 639
  • 4
  • 8