[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
});
[AngularJS] Catching errors with $exceptionHandler的更多相关文章
- ora-00600笔记
一. ORA-600 概述 Errorsof the form ORA-600 are called internal errors. This section clarifies themisund ...
- oracle-Expdp/impdp命令
建立逻辑路径 create or replace directory dumpdir as 'c:\'; grant read,write on directory dumpdir to scott; ...
- java 异常处理 Throwable Error 和Exception
Java异常类层次结构图: 异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.事实上,异常本质上是程序上的错误,包括程序逻辑错误和系统错误. 比如使用 ...
- 『Python』 多线程 端口扫描器
0x 00 Before Coding 当端口打开时,向端口发送 TCP SYN 请求,会返回一个 ACK 响应: 当端口关闭,返回的是 RST 响应: 0x 01 Coding 可以用 socke ...
- Powershell错误处理,try catch finally
脚本的调试向来是一个艰巨的任务,在powershell出现以前简直是一场灾难.在powershell中微软终于做出了诸多改进,不但有了$Error.-whatif,也有了ISE.而在语法上也增加了tr ...
- Code Complete阅读笔记(二)
2015-03-06 328 Unusual Data Types ——You can carry this technique to extremes,putting all the ...
- React源码解析:setState
先来几个例子热热身: ......... constructor(props){ super(props); this.state = { index: 0 } } componentDidMount ...
- 解决 ASP.NET Core 自定义错误页面对 Middleware 异常无效的问题
我们基于 Razor Class Library 实现了自定义错误页面的公用类库(详见之前的随笔),但是在实际使用时发现如果在 middleware 中发生了异常,则不能显示自定义错误页面,而是返回默 ...
- django之signal机制再探
djangobb中的signal post_save信号调用send函数时,为什么它会对与topic.post相关的其他models进行修改?同一个信号,例如post_save(保存过后的处理),是所 ...
随机推荐
- bzoj3294
感觉自己就是不怎么擅长计数的问题 设f[k,i,j]表示前k种颜色占据了i行j列的方案 g[k,i,j]表示第k种颜色占据了i行j列的方案,注意要减去并没占据满i行j列的情况 然后转移就很好写了 像这 ...
- Maven配置文件Pom.xml详解
<project xmlns="http://maven.apache.org/POM/4.0.0 " xmlns:xsi="http://www.w3. ...
- java、myeclipse常见错误的解决(未完)
1.报错java.lang.NoClassDefFoundError ,但是相关jar包已经导入工程. 解决方案:将jar包放入C盘tomcat上部署的相应项目中的WEB-INF/lib中.web容器 ...
- MSP430的看门狗常见用法以及中断函数的书写方法
今天下午看了一下MSP430的看门狗的基本用法 看门狗是为了防止程序跑飞而设定的,但是由于看门狗是一个类似于定时器,因此可以把他当作定时器来使用 示例代码:用看门狗定时器使一个led闪烁 #inclu ...
- 烧写u_boot系统和linux系统
今天下午准备烧写一下u_boot还有linux系统,因为是笔记本电脑,吐槽一下,笔记本电脑的usb转串口不是怎么稳定,dnw下对应的驱动也不怎么好用,导致在笔记本电脑上烧写系统的成功率比较低,本来三点 ...
- LeetCode题解——ZigZag Conversion
题目: 把一个字符串按照Z型排列后打印出来,例如 "PAYPALISHIRING" 重新排列后为3行,即 P A H N A P L S I I G Y I R 那么输出为&quo ...
- ZOJ Light Bulb - 3203
题意:人左右走动,求影子L的最长长度. 思路:三分人在D上的位置.注意影子长=D-x+H-(H-h)*D/x. #include<iostream> #include<stdio.h ...
- uva11732 strcmp() Anyone?
题意:给出多个字符串,两两配对,求总配对次数. 思路:如果两个字符串一样,ans=strlen(字符串)*2+2,如果不同,ans=公共前缀长度*2+1:用左儿子右兄弟建字典树.插入一个字符计算一次. ...
- HDU-4612 Warm up 边双连通分量+缩点+最长链
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 简单图论题,先求图的边双连通分量,注意,此题有重边(admin还逗比的说没有重边),在用targ ...
- linux内存负载分析
衡量内存负载的一个很重要的指标就是页面置换的频率.当linux系统频繁的对页进行换进换出 的时候,说明物理内存不过,不得不进行频繁的置换页面. 使用vmstat(virtual memory stat ...