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.
 
     
    