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
});

[AngularJS] Catching errors with $exceptionHandler的更多相关文章

  1. ora-00600笔记

    一. ORA-600 概述 Errorsof the form ORA-600 are called internal errors. This section clarifies themisund ...

  2. oracle-Expdp/impdp命令

    建立逻辑路径 create or replace directory dumpdir as 'c:\'; grant read,write on directory dumpdir to scott; ...

  3. java 异常处理 Throwable Error 和Exception

    Java异常类层次结构图:       异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.事实上,异常本质上是程序上的错误,包括程序逻辑错误和系统错误. 比如使用 ...

  4. 『Python』 多线程 端口扫描器

    0x 00 Before Coding 当端口打开时,向端口发送 TCP SYN 请求,会返回一个 ACK 响应: 当端口关闭,返回的是 RST 响应: 0x 01 Coding  可以用 socke ...

  5. Powershell错误处理,try catch finally

    脚本的调试向来是一个艰巨的任务,在powershell出现以前简直是一场灾难.在powershell中微软终于做出了诸多改进,不但有了$Error.-whatif,也有了ISE.而在语法上也增加了tr ...

  6. Code Complete阅读笔记(二)

    2015-03-06   328   Unusual Data Types    ——You can carry this technique to extremes,putting all the ...

  7. React源码解析:setState

    先来几个例子热热身: ......... constructor(props){ super(props); this.state = { index: 0 } } componentDidMount ...

  8. 解决 ASP.NET Core 自定义错误页面对 Middleware 异常无效的问题

    我们基于 Razor Class Library 实现了自定义错误页面的公用类库(详见之前的随笔),但是在实际使用时发现如果在 middleware 中发生了异常,则不能显示自定义错误页面,而是返回默 ...

  9. django之signal机制再探

    djangobb中的signal post_save信号调用send函数时,为什么它会对与topic.post相关的其他models进行修改?同一个信号,例如post_save(保存过后的处理),是所 ...

随机推荐

  1. POJ3921

    搜索 每次找出最短路 如果小于等于k 那么必定这里有一点是要被删掉的 枚举这个最短路径上的每一个点 (一般不会超过20) 将其相邻边删除 用dijskra求最短路径并且保存即可 深度搜索 #inclu ...

  2. LeeCode Algorithm #3 Longest Substring Without Repeating Characters

    一开始以为是不连续的,其实要求子串是连续的.想法:two-pointer O(n)时间,再借助256大小的int数组.两个下标i,j(i<=j).对于i=0,找到最右侧的字符不重复的下标的后一位 ...

  3. BMap介绍

    API引用路径: <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&am ...

  4. 十个拥有丰富UI组件的JS开发框架

    如今,网上有各种各样的 JavaScript 框架用来简化 Web 应用开发.这些框架都提供了一些核心的特性,例如 DOM 操作,动画,事件处理以及 Ajax 交互,但不是都带有 UI 组件.今天这篇 ...

  5. css padding在ie7、ie6、firefox中的兼容问题

    padding 简写属性在一个声明中设置所有内边距属性. 说明这个简写属性设置元素所有内边距的宽度,或者设置各边上内边距的宽度.行内非替换元素上设置的内边距不会影响行高计算:因此,如果一个元素既有内边 ...

  6. Mint Linuxubuntu 字体配置文件

    <?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"><fon ...

  7. WebDriver 运行模式下使用rc 代码

    selenium2 对之前的rc 代码提供了兼容性接口,如果你之前的code 都是用rc 写,而现在又想摆脱要每次启动server,你只需要 略做修改即可.代码如下: public class Tes ...

  8. python引用在函数传参时的体现以及可变与不可变对象的对比

    今天偶然看到 vamei 老师的博客 http://www.cnblogs.com/vamei/archive/2012/07/10/2582795.html 讲的是python动态类型以及引用的事儿 ...

  9. STM32 串口功能 库函数 详解和DMA 串口高级运用(转载)

    数据传输时要从支持那些相关的标准?传输的速度?什么时候开始?什么时候结束?传输的内容?怎样防止通信出错?数据量大的时候怎么弄?硬件怎么连接出发,当然对于stm32还要熟悉库函数的功能 具起来rs232 ...

  10. 在ASP.NET MVC中修改默认代码生成/支架模板

    到 C:\Program Files (or x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp (or Visual ...