Flutter异常搜集和上报

简介

Flutter中的异常虽然不像Native那样会直接导致app crash,但也是不容忽视的. 比如widget构建失败,又或是某个网络请求解析失败,所以针对flutter我们也需要有一套规则来捕捉异常,下面主要是介绍异常类型, 全局异常捕捉的三种方式、异常报告的几种形式, 在查看了Isolate,Future,FlutterError.onError,相关的代码实践出来的.

Flutter中常见的异常

Flutter中最最常见的就是空指针异常了,关于可选类型这块始终是Flutter这门语言的痛点之一,总之Flutter在数据结构转换这块和可选类型和移动端语言还是有很大差距的,希望官方快点优化吧。

字典转换,类型推倒,文件读取,网络请求错误,布局溢出,数组越界等,插件通信异常等等,通常用Error和Exception来描述

1.Error: 用于定义程序执行错误的对象

Error (dart.core)
    AsyncError (dart.async) 
    JsonUnsupportedObjectError (dart.convert)
        JsonCyclicError (dart.convert)
    LateInitializationErrorImpl (dart._internal)
    FlutterError (assertions.dart)
    RemoteError (dart.isolate)
    UnderflowError (quiver.async)
    MatchError (quiver.testing.equality)
    FallThroughError (dart.core)
    CastError (dart.core)
    UnsupportedError (dart.core)
        UnimplementedError (dart.core)
    ConcurrentModificationError (dart.core)
    LateInitializationError (dart.core)
        LateInitializationErrorImpl (dart._internal)
    OutOfMemoryError (dart.core)
    AbstractClassInstantiationError (dart.core)
    NoSuchMethodError (dart.core)
    TypeError (dart.core)
    UnimplementedError (dart.core)
    NullThrownError (dart.core)
    AssertionError (dart.core)
        FlutterError (assertions.dart)
    StackOverflowError (dart.core)
    CyclicInitializationError (dart.core)
    StateError (dart.core)
    ArgumentError (dart.core)
        IndexError (dart.core)
        RangeError (dart.core)

2.Exception: 由dartVM和自定义的dart代码手动抛出

Exception (dart.core)
    DeferredLoadException (dart.async)
    TimeoutException (dart.async)
    IsolateSpawnException (dart.isolate)
    IOException (dart.io)
        HttpException (dart._http)
        WebSocketException (dart._http)
        FileSystemException (dart.io)
        ProcessException (dart.io)
        SignalException (dart.io)
        TlsException (dart.io)
        SocketException (dart.io)
        StdoutException (dart.io)
        StdinException (dart.io)
    PlatformException (message_codec.dart)
    MissingPluginException (message_codec.dart)
    Tic

你可能感兴趣的:(Android,程序人生,程序员,flutter,javascript,android)