Files
sdk/tests/language/exception/try_catch_optimized5_test.dart
T
Robert Nystrom 74ef393e6d Migrate language_2/exception to NNBD.
Change-Id: I0f758fce0af79be77b2fc885afcc3bd17d9fb55e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142701
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2020-04-07 22:13:46 +00:00

74 lines
1.7 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.
// Dart test program for testing try/catch statement without any exceptions
// being thrown.
// VMOptions=--optimization-counter-threshold=100 --no-background-compilation
// Test optional parameters updated inside try-catch
import "package:expect/expect.dart";
@pragma('vm:never-inline')
m1(int b) {
if (b == 1) throw 123;
}
@pragma('vm:never-inline')
m2(int b) {
if (b == 2) throw 456;
}
@pragma('vm:never-inline')
test1(int b, [int state = 0]) {
try {
state++;
m1(b);
state++;
m2(b);
state++;
} catch (e, s) {
if (b == 1 && state != 1) throw "fail1";
if (b == 2 && state != 2) throw "fail2";
if (b == 3 && state != 3) throw "fail3";
if (s is! StackTrace) throw "fail4";
return e;
}
return "no throw";
}
@pragma('vm:never-inline')
test2(int b, [int state = -1]) {
state = 0;
try {
state++;
m1(b);
state++;
m2(b);
state++;
} catch (e, s) {
if (b == 1 && state != 1) throw "fail1";
if (b == 2 && state != 2) throw "fail2";
if (b == 3 && state != 3) throw "fail3";
if (s is! StackTrace) throw "fail4";
return e;
}
return "no throw";
}
main() {
for (var i = 0; i < 300; i++) {
Expect.equals("no throw", test1(0));
}
Expect.equals("no throw", test1(0));
Expect.equals(123, test1(1));
Expect.equals(456, test1(2));
for (var i = 0; i < 300; i++) {
Expect.equals("no throw", test2(0));
}
Expect.equals("no throw", test2(0));
Expect.equals(123, test2(1));
Expect.equals(456, test2(2));
}