加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

异常处理 – Angular2:捕获角度异常

发布时间:2020-12-17 17:50:03 所属栏目:安全 来源:网络整理
导读:如果Angular2遇到内部异常,它将不会记录到控制台.如何检测以下异常? EXCEPTION: Error during instantiation of MainFormComponent!.ORIGINAL EXCEPTION: TypeError: Cannot set property 'crashMeMaybe' of undefinedORIGINAL STACKTRACE:... stacktrace .
如果Angular2遇到内部异常,它将不会记录到控制台.如何检测以下异常?

EXCEPTION: Error during instantiation of MainFormComponent!.
ORIGINAL EXCEPTION: TypeError: Cannot set property 'crashMeMaybe' of undefined
ORIGINAL STACKTRACE:
... stacktrace ...
ERROR CONTEXT:
... context object ...

有没有可用的订阅?这样的文件在哪里?

解决方法

有一个界面ExceptionHandler,您可以通过它提供您选择的自定义实现.见 here和 documentation.

来自BETA.0来源:(facade / exception_handler.d.ts)

/**
 * Provides a hook for centralized exception handling.
 *
 * The default implementation of `ExceptionHandler` prints error messages to the `Console`. To
 * intercept error handling,* write a custom exception handler that replaces this default as appropriate for your app.
 *
 * ### Example
 *
 * ```javascript
 *
 * class MyExceptionHandler implements ExceptionHandler {
 *   call(error,stackTrace = null,reason = null) {
 *     // do something with the exception
 *   }
 * }
 *
 * bootstrap(MyApp,[provide(ExceptionHandler,{useClass:    MyExceptionHandler})])
 *
 * ```
 */

更新:

我对BETA.0有点问题

>进口必须被黑客入侵,
>界面似乎被内部细节污染了.

我运行它像:

import {ExceptionHandler} from 'angular2/src/facade/exception_handler';

export interface IExceptionHandler {
    call(exception: any,stackTrace?: any,reason?: string): void;
}

export class CustomExceptionHandler implements IExceptionHandler {
    call(exception: any,stackTrace: any,reason: string): void {
        alert(exception);
    }
}

bootstrap(DemoApp,[
    new Provider(ExceptionHandler,{
        useClass: CustomExceptionHandler
    })
]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读