Unverified Commit c849ffd3 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

FlutterErrorDetails.context docs fix (#55001)

parent 26516817
...@@ -10,6 +10,9 @@ import 'diagnostics.dart'; ...@@ -10,6 +10,9 @@ import 'diagnostics.dart';
import 'print.dart'; import 'print.dart';
import 'stack_frame.dart'; import 'stack_frame.dart';
// Examples can assume:
// String runtimeType;
/// Signature for [FlutterError.onError] handler. /// Signature for [FlutterError.onError] handler.
typedef FlutterExceptionHandler = void Function(FlutterErrorDetails details); typedef FlutterExceptionHandler = void Function(FlutterErrorDetails details);
...@@ -281,7 +284,7 @@ class ErrorSummary extends _ErrorDiagnostic { ...@@ -281,7 +284,7 @@ class ErrorSummary extends _ErrorDiagnostic {
/// An [ErrorHint] provides specific, non-obvious advice that may be applicable. /// An [ErrorHint] provides specific, non-obvious advice that may be applicable.
/// ///
/// If your message provides obvious advice that is always applicable it is an /// If your message provides obvious advice that is always applicable, it is an
/// [ErrorDescription] not a hint. /// [ErrorDescription] not a hint.
/// ///
/// See also: /// See also:
...@@ -325,7 +328,30 @@ class ErrorSpacer extends DiagnosticsProperty<void> { ...@@ -325,7 +328,30 @@ class ErrorSpacer extends DiagnosticsProperty<void> {
/// Class for information provided to [FlutterExceptionHandler] callbacks. /// Class for information provided to [FlutterExceptionHandler] callbacks.
/// ///
/// See [FlutterError.onError]. /// {@tool snippet}
/// This is an example of using [FlutterErrorDetails] when calling
/// [FlutterError.reportError].
///
/// ```dart
/// void main() {
/// try {
/// // Try to do something!
/// } catch (error) {
/// // Catch & report error.
/// FlutterError.reportError(FlutterErrorDetails(
/// exception: error,
/// library: 'Flutter test framework',
/// context: ErrorSummary('while running async test code'),
/// ));
/// }
/// }
/// ```
/// {@end-tool}
///
/// See also:
///
/// * [FlutterError.onError], which is called whenever the Flutter framework
/// catches an error
class FlutterErrorDetails with Diagnosticable { class FlutterErrorDetails with Diagnosticable {
/// Creates a [FlutterErrorDetails] object with the given arguments setting /// Creates a [FlutterErrorDetails] object with the given arguments setting
/// the object's properties. /// the object's properties.
...@@ -382,13 +408,45 @@ class FlutterErrorDetails with Diagnosticable { ...@@ -382,13 +408,45 @@ class FlutterErrorDetails with Diagnosticable {
/// the console. /// the console.
final String library; final String library;
/// A human-readable description of where the error was caught (as opposed to /// A [DiagnosticsNode] that provides a human-readable description of where
/// where it was thrown). /// the error was caught (as opposed to where it was thrown).
///
/// The node, e.g. an [ErrorDescription], should be in a form that will make
/// sense in English when following the word "thrown", as in "thrown while
/// obtaining the image from the network" (for the context "while obtaining
/// the image from the network").
///
/// {@tool snippet}
/// This is an example of using and [ErrorDescription] as the
/// [FlutterErrorDetails.context] when calling [FlutterError.reportError].
///
/// ```dart
/// void maybeDoSomething() {
/// try {
/// // Try to do something!
/// } catch (error) {
/// // Catch & report error.
/// FlutterError.reportError(FlutterErrorDetails(
/// exception: error,
/// library: 'Flutter test framework',
/// context: ErrorDescription('while dispatching notifications for $runtimeType'),
/// ));
/// }
/// }
/// ```
/// {@end-tool}
///
/// See also:
/// ///
/// The string should be in a form that will make sense in English when /// * [ErrorDescription], which provides an explanation of the problem and
/// following the word "thrown", as in "thrown while obtaining the image from /// its cause, any information that may help track down the problem,
/// the network" (for the context "while obtaining the image from the /// background information, etc.
/// network"). /// * [ErrorSummary], which provides a short (one line) description of the
/// problem that was detected.
/// * [ErrorHint], which provides specific, non-obvious advice that may be
/// applicable.
/// * [FlutterError], which is the most common place to use
/// [FlutterErrorDetails].
final DiagnosticsNode context; final DiagnosticsNode context;
/// A callback which filters the [stack] trace. Receives an iterable of /// A callback which filters the [stack] trace. Receives an iterable of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment