Files
sdk/tests/language/exception/try_multiple_catch_async.dart
T
Ömer Sinan Ağacan 6de879e0f5 [dart2wasm] Fix exception handling in async functions
Fixes #55347.

Change-Id: I9ced2a4c06e6cb9714dc47e3661f5582c70cdeb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361063
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-04-05 14:23:00 +00:00

53 lines
1.3 KiB
Dart

// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests try-catch in `async`, with multiple `catch`/`on` blocks, where the
// first type test in the `catch`/`on` blocks fail and the subsequent test
// passes.
//
// This is a regression test for issue #55347.
import 'package:expect/expect.dart';
class MyException implements Exception {
MyException([this.message]);
final String? message;
@override
String toString() => 'MyException($message)';
}
class MyOtherException implements Exception {
MyOtherException([this.message]);
final String? message;
@override
String toString() => 'MyOtherException($message)';
}
Future<String> asynchronouslyThrowException() async {
throw MyException('Throwing an error!');
}
Future<String?> test() async {
try {
await asynchronouslyThrowException();
Expect.fail('Exception is not thrown');
} on MyOtherException {
Expect.fail('Wrong exception caught');
} on MyException {
return 'Success';
} catch (error) {
Expect.fail('Wrong exception caught');
}
Expect.fail('No exception caught');
return null;
}
void main() async {
Expect.equals(await test(), 'Success');
}