Exception mechanism in angular and processing outside exception

  After consulting the official documentation of angularjs, I found that the throw exception is mentioned in the documentation.

angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
  return function(exception, cause) {
    exception.message += ' (caused by "' + cause + '")';
    throw exception;
  };
});

  Catching exceptions is also mentioned below:

try { ... } catch(e) { $exceptionHandler(e); }

  In fact, these two are often used in js exception handling, but what is the difference between this and js? Let's continue to verify that in angluarjs, to handle exceptions, you must use the $ExceptionHander component in the service service , after the component is introduced, you can boldly deal with bugs that you don't want to debug. Here's an example:

var module = angular.module("apple", []);
module = [ '$scope' , '$exceptionHandler' , function ( scope, exceptlogger) {....
try { function body } catch(e) {exceptlogger(e); }

  When working on the project, it is found that if there is an error in the method of calling the plug-in, such as uncaught exception, etc., this way of capturing cannot catch the exception, then we should use another way of capturing the exception.

  Use the method of window.onerror to catch exceptions:

//Catch errors inside or outside the function
window.onerror = fnErrorTrap;
    function fnErrorTrap(msg,url){
               console.log( "Error: " + msg+ "URL: " + url);
    //Note that the return value below is true, which means that the browser will not handle this error and will not display an error message
                     return true;
     }

 

Article source: http://www.cnblogs.com/2014-1130/p/4847580.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326485496&siteId=291194637