[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(保存过后的处理),是所 ...
随机推荐
- 【原创】深度神经网络(Deep Neural Network, DNN)
线性模型通过特征间的现行组合来表达“结果-特征集合”之间的对应关系.由于线性模型的表达能力有限,在实践中,只能通过增加“特征计算”的复杂度来优化模型.比如,在广告CTR预估应用中,除了“标题长度.描述 ...
- Warning: Name is nonexistent or not a directory
Every time I start up MATLAB, I receive this message: Warning: Name is nonexistent or not a director ...
- memcached性能监控
在上文“在Windows .NET平台下使用Memcached”中,我给大家介绍了如何在Windows平台上部署Memecached服务端,如何在.NET平台中应用Memcached,详细介绍了两种流 ...
- Initializing nested object properties z
public class Employee { public Employee() { this.Insurance = new Insurance(); } // Perhaps another c ...
- ASDL + WN725N 配置无线AP
1. ASDL 正常拨号上网 2. 安装TP-LINK无线客户端应用程序 打开之后选择模拟AP 如下图设置----应用 3. 本地连接----属性----高级 如下图设置 4. 宽带连接--- ...
- NOIP2014 无线网络发射器选址
1.无线网络发射器选址 (wireless.cpp/c/pas) [问题描述] 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平 ...
- Mysql engine
MySQL engine.type类型的区别:
- [转载] Zookeeper中的 ACL(Access Control List)访问控制列表
zk做为分布式架构中的重要中间件,通常会在上面以节点的方式存储一些关键信息,默认情况下,所有应用都可以读写任何节点,在复杂的应用中,这不太安全,ZK通过ACL机制来解决访问权限问题,详见官网文档:ht ...
- HDU-4675 GCD of Sequence 数学
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给一个大小为N的数列a[i],然后一个数M以及一个数K,要你求得一个数列b[i],其中b[ ...
- Java网络编程(TCP协议-服务端和客户端交互)
客户端: package WebProgramingDemo; import java.io.IOException; import java.io.InputStream; import java. ...