Skip to content

Commit

Permalink
Improve PlatformException#stacktrace docs for Android (#104331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ueman authored May 31, 2022
1 parent bb30bfd commit f9ac22a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/flutter/lib/src/services/message_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,51 @@ class PlatformException implements Exception {
/// print(stacktrace);
/// }
/// ```
///
/// On Android this field is populated when a `RuntimeException` or a subclass of it is thrown in the method call handler,
/// as shown in the following example:
///
/// ```kotlin
/// import androidx.annotation.NonNull
/// import io.flutter.embedding.android.FlutterActivity
/// import io.flutter.embedding.engine.FlutterEngine
/// import io.flutter.plugin.common.MethodChannel
///
/// class MainActivity: FlutterActivity() {
/// private val CHANNEL = "channel_name"
///
/// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
/// super.configureFlutterEngine(flutterEngine)
/// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
/// call, result -> throw RuntimeException("Oh no")
/// }
/// }
/// }
/// ```
///
/// It is also populated on Android if the method channel result is not serializable.
/// If the result is not serializable, an exception gets thrown during the serialization process.
/// This can be seen in the following example:
///
/// ```kotlin
/// import androidx.annotation.NonNull
/// import io.flutter.embedding.android.FlutterActivity
/// import io.flutter.embedding.engine.FlutterEngine
/// import io.flutter.plugin.common.MethodChannel
///
/// class MainActivity: FlutterActivity() {
/// private val CHANNEL = "channel_name"
///
/// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
/// super.configureFlutterEngine(flutterEngine)
/// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
/// call, result -> result.success(Object())
/// }
/// }
/// }
/// ```
///
/// In the cases described above, the content of [stacktrace] will be the unprocessed output of calling `toString()` on the exception.
final String? stacktrace;

@override
Expand Down

0 comments on commit f9ac22a

Please sign in to comment.