• 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
16function main() : void {
17    let caught_counter = 0;
18
19    let INT_ONE : int = 1;
20    let INT_ZERO : int = 0;
21    let LONG_ONE : long = 1;
22    let LONG_ZERO : long = 0;
23
24    try {
25        let result : int = INT_ONE / INT_ZERO;
26    } catch (error: ArithmeticError) {
27        caught_counter++;
28    }
29    assertEQ(caught_counter, 1)
30
31    try {
32        let result : long = LONG_ONE / LONG_ZERO;
33    } catch (error: ArithmeticError) {
34        caught_counter++;
35    }
36    assertEQ(caught_counter, 2)
37
38    try {
39        let result : int = INT_ONE % INT_ZERO;
40    } catch (error: ArithmeticError) {
41        caught_counter++;
42    }
43    assertEQ(caught_counter, 3)
44
45    try {
46        let result : long = LONG_ONE % LONG_ZERO;
47    } catch (error: ArithmeticError) {
48        caught_counter++;
49    }
50    assertEQ(caught_counter, 4)
51
52    let DOUBLE_ONE : double = 1.0;
53    let DOUBLE_ZERO : double = 0.0;
54
55    try {
56        let result : double = DOUBLE_ONE / DOUBLE_ZERO;
57    } catch (error: ArithmeticError) {
58        assertTrue(false)
59    }
60
61    try {
62        let result = INT_ONE / DOUBLE_ZERO;
63    } catch (error: ArithmeticError) {
64        assertTrue(false)
65    }
66
67    try {
68        let result = DOUBLE_ONE / INT_ZERO;
69    } catch (error: ArithmeticError) {
70        assertTrue(false)
71    }
72
73    try {
74        let result : double = DOUBLE_ONE % DOUBLE_ZERO;
75    } catch (error: ArithmeticError) {
76        assertTrue(false)
77    }
78
79    try {
80        let result = INT_ONE % DOUBLE_ZERO;
81    } catch (error: ArithmeticError) {
82        assertTrue(false)
83    }
84
85    try {
86        let result = DOUBLE_ONE % INT_ZERO;
87    } catch (error: ArithmeticError) {
88        assertTrue(false)
89    }
90}
91