• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16class TestException extends Exception {}
17
18let catchCode = 0;
19
20function main(): void {
21  try {
22    throw new NullPointerError();
23  } catch (e: NullPointerError) {
24    catchCode = 1;
25  } catch (e: Error) {
26    assertTrue(false)
27  } catch (e) {
28    assertTrue(false)
29  }
30
31  assertEQ(catchCode, 1)
32
33  try {
34    throw new NullPointerError();
35  } catch (e: Error) {
36    catchCode = 2;
37  } catch (e: NullPointerError) {
38    assertTrue(false)
39  } catch (e) {
40    assertTrue(false)
41  }
42
43  assertEQ(catchCode, 2)
44
45  try {
46    throw new TestException();
47  } catch(e: TestException) {
48    catchCode = 3;
49  } catch (e: Exception) {
50    assertTrue(false)
51  } catch (e) {
52    assertTrue(false)
53  }
54
55  assertEQ(catchCode, 3)
56
57  try {
58    throw new TestException();
59  } catch (e: Exception) {
60    catchCode = 4;
61  } catch (e: TestException) {
62    assertTrue(false)
63  } catch (e) {
64    assertTrue(false)
65  }
66
67  assertEQ(catchCode, 4)
68}
69