dart-sdk/tests/language_2/try_finally_regress_25333_test.dart
Janice Collins e166ab3e2b Migrate test block 160 to Dart 2.0.
Successfully migrated 7 tests. Need manual work on 6 tests:
- language_2/try_catch_test.dart:
  (TODO) Merge from language/try_catch_test.dart into this file.
- language_2/type_argument_in_super_type_test.dart:
  (TODO) Ensure code that checks for a TypeError uses 2.0 semantics.
- language_2/type_check_const_function_typedef2_test.dart:
  (TODO) Fix code that mentions "checked" mode.
- language_2/type_checks_in_factory_method_test.dart:
  (TODO) Ensure code that checks for a TypeError uses 2.0 semantics.
- language_2/type_conversion_ssa_test.dart:
  (TODO) Fix code that mentions "checked" mode.
- language_2/type_error_test.dart:
  (TODO) Merge from language/type_error_test.dart into this file.
  (TODO) Ensure code that checks for a TypeError uses 2.0 semantics.


Bug:
Change-Id: I43901890540efcf55da13d013571ce91979cbb64
Reviewed-on: https://dart-review.googlesource.com/11142
Commit-Queue: Janice Collins <jcollins@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2017-10-10 15:55:32 +00:00

65 lines
1.3 KiB
Dart

// Copyright (c) 2016, 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.
// Test correct handling of try-catch inside try-finally.
import "package:expect/expect.dart";
void main() {
print("== test1 ==");
bool caught = false;
try {
test1();
print("Unexpected 1"); // should never go here
Expect.isTrue(false);
} catch (e) {
caught = true;
print("main catch 1: $e");
Expect.equals(e, "Ball");
}
Expect.isTrue(caught);
print("== test2 ==");
caught = false;
try {
test2();
print("Unexpected 2"); // should never go here
Expect.isTrue(false);
} catch (e) {
caught = true;
print("main catch 2: $e");
Expect.equals(e, "Ball");
}
Expect.isTrue(caught);
}
void test1() {
try {
throw "Ball";
} finally {
try {
throw "Frisbee";
} catch (e) {
print("test 1 catch: $e");
Expect.equals(e, "Frisbee");
}
}
}
void test2() {
try {
throwError(); // call a method that throws an error
} finally {
try {
throw "Frisbee";
} catch (e) {
print("test 2 catch: $e");
Expect.equals(e, "Frisbee");
}
}
}
void throwError() {
throw "Ball";
}