zoukankan      html  css  js  c++  java
  • [AngularJS] Catching errors with $exceptionHandler

    The AngularJS $exceptionHandler service allows you to catch and handle unanticipated JavaScript errors in a meaningful way.

    So when application is under building process, can create a $exceptionHandler service to log out the uncatch exception.

    angular.module('app', [])
        .factory('$exceptionHandler', function ($injector) {
            return function (exception, cause) {
                var $rootScope = $injector.get('$rootScope');
                $rootScope.errors = $rootScope.errors || [];
                $rootScope.errors.push(exception.message);
                console.log($rootScope.errors);
            }
        })
        .run(function ($http) {
    
            function onSuccess (result) {
                console.log('hooray data!');
                console.log(result.data.length, 'repos found');
                result.count(); // This is no count() method on the result object.
            }
    
            function onFailure (info) {
                console.log('boo error :(');
                console.log(info);
            }
    
            $http.get('https://api.github.com/users/bclinkinbeard/repos')
                .then(onSuccess, onFailure); // We can catch $http return failure but there could be some uncatch failure in some place
        });
  • 相关阅读:
    Linux文本处理命令
    管道和重定向
    Linux网络基本配置
    网络基础
    普通权限和特殊权限
    Linux权限
    Linux用户
    Linux帮助文档
    创建新表,自动授权trigger
    禁用约束语法测试
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4320681.html
Copyright © 2011-2022 走看看