//http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning
One possibility is to set your own error handler before the call and restore the previous error handler later with restore_error_handler(). set_error_handler(function() { /* ignore errors */ });
dns_get_record();
restore_error_handler();
You could build on this idea and write a re-usable error handler that logs the errors for you. set_error_handler([$logger, 'onSilencedError']);
dns_get_record();
restore_error_handler();
Turning errors into exceptions You can use set_error_handler() and the ErrorException class to turn all php errors into exceptions. set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
} throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}); try {
dns_get_record();
} catch (ErrorException $e) {
// ...
} The important thing to note when using your own error handler is that it will bypass the error_reporting setting and pass all errors (notices, warnings, etc.) to your error handler. You can set a second argument on set_error_handler() to define which error types you want to receive, or access the current setting using ... = error_reporting() inside the error handler.

[php] try - catch exceptiong handler的更多相关文章

  1. Socket聊天程序——服务端

    写在前面: 昨天在博客记录自己抽空写的一个Socket聊天程序的初始设计,那是这个程序的整体设计,为了完整性,今天把服务端的设计细化记录一下,首页贴出Socket聊天程序的服务端大体设计图,如下图: ...

  2. 30 分钟开发一个简单的 watchOS 2 app <oneVcat>

    Apple Watch 和 watchOS 第一代产品只允许用户在 iPhone 设备上进行计算,然后将结果传输到手表上进行显示.在这个框架下,手表充当的功能在很大程度上只是手机的另一块小一些的显示器 ...

  3. 在 Area 中使用RouteAttribute 定义路由, 并支持多语言

    业务上的一个需求, 同一页面, 两种不同的使用方法, 为了区分这两种需求, 需要加一个参数到 URL 中,不改路由的话, 是这样: http://localhost:16269/en-US/Forwa ...

  4. (C++) Interview in English. - Constructors/Destructors

    Constructors/Destructors. 我们都知道,在C++中建立一个类,这个类中肯定会包括构造函数.析构函数.复制构造函数和重载赋值操作:即使在你没有明确定义的情况下,编译器也会给你生成 ...

  5. 【JavaScript】JavaScript Promise 探微

    http://www.html-js.com/article/Promise-translation-JavaScript-Promise-devil-details 原文链接:JavaScript ...

  6. How a C++ compiler implements exception handling

    Introduction One of the revolutionary features of C++ over traditional languages is its support for ...

  7. .10-Vue源码之Watcher(1)

    上一节最后再次调用了mount函数,我发现竟然跳到了7000多行的那个函数,之前我还说因为声明早了被覆盖,看来我错了! 就是这个函数: // Line-7531 Vue$3.prototype.$mo ...

  8. [CLR via C#]异常和状态管理

    当CLR检测到某个正在运行的.NET应用程序处于一种特殊的正常执行顺序被打断的状态时,会生成一个异常对象来表示这个错误,并将此对象在方法调用堆栈中向上传送.如果一个程序引发了一个异常却没有处理,CLR ...

  9. Let's do our own full blown HTTP server with Netty--转载

    原文地址:http://adolgarev.blogspot.com/2013/12/lets-do-our-own-full-blown-http-server.html Sometimes ser ...

随机推荐

  1. SQL 存储过程 超市小票打印

    create database chaoshils--创建一个数据库 go use chaoshils--使用这个数据库 go create table gongying--创建一个供应商的表格 ( ...

  2. pod优先级与抢占测试

    # kubectl describe node k8s-n2Name:               k8s-n2Roles:              <none>Labels:      ...

  3. js:Date格式化

    将Date类型格式化为"yyyy/MM/dd HH:mm:ss" 函数代码如下: //Date的prototype 属性可以向对象添加属性和方法. Date.prototype.F ...

  4. 百度BAE的使用

  5. 使用maven将项目热发布到tomcat7的坑

    首先是配置tomcat的用户权限问题,最好是配置最大的权限,要不然会报错,我之前就是一直报错 <role rolename="manager"/> <user u ...

  6. iOS - OC - JSON 解析 - NSJSONSerialization

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  7. [leetcode]257. Binary Tree Paths二叉树路径

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  8. Maven核心简析

    本文以类图的方式,介绍maven核心的12个概念以及相互之间的关系. Table of Contents 1 maven管理的目标:工程(Project) 1.1 工程依赖关系 1.2 工程聚合关系 ...

  9. spring框架之数组,集合(List,Set,Map),Properties等的注入

    先编写User类: package com.huida.demo4; import java.util.Arrays; import java.util.List; import java.util. ...

  10. jQuery中animate()对Firefox无效的解决办法

    在使用 animate()做返回顶部的动画时,会出现对Firefox无效的情况,如: $('body').animate({scrollTop:'0'},500); 它对Chrome,IE,Opera ...