• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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    try {
20        let result : int = 1 / 0;
21    } catch (error: ArithmeticException) {
22        caught_counter++;
23    }
24    assert caught_counter == 1;
25
26    try {
27        let result : long = 1 / 0;
28    } catch (error: ArithmeticException) {
29        caught_counter++;
30    }
31    assert caught_counter == 2;
32
33    try {
34        let result : int = 1 % 0;
35    } catch (error: ArithmeticException) {
36        caught_counter++;
37    }
38    assert caught_counter == 3;
39
40    try {
41        let result : long = 1 % 0;
42    } catch (error: ArithmeticException) {
43        caught_counter++;
44    }
45    assert caught_counter == 4;
46
47    let INT_ONE : int = 1;
48    let INT_ZERO : int = 0;
49    let LONG_ONE : long = 1;
50    let LONG_ZERO : long = 0;
51
52    try {
53        let result : int = INT_ONE / INT_ZERO;
54    } catch (error: ArithmeticException) {
55        caught_counter++;
56    }
57    assert caught_counter == 5;
58
59    try {
60        let result : long = LONG_ONE / LONG_ZERO;
61    } catch (error: ArithmeticException) {
62        caught_counter++;
63    }
64    assert caught_counter == 6;
65
66    try {
67        let result : int = INT_ONE % INT_ZERO;
68    } catch (error: ArithmeticException) {
69        caught_counter++;
70    }
71    assert caught_counter == 7;
72
73    try {
74        let result : long = LONG_ONE % LONG_ZERO;
75    } catch (error: ArithmeticException) {
76        caught_counter++;
77    }
78    assert caught_counter == 8;
79
80    let DOUBLE_ONE : double = 1.0;
81    let DOUBLE_ZERO : double = 0.0;
82
83    try {
84        let result : double = DOUBLE_ONE / DOUBLE_ZERO;
85    } catch (error: ArithmeticException) {
86        assert false;
87    }
88
89    try {
90        let result = INT_ONE / DOUBLE_ZERO;
91    } catch (error: ArithmeticException) {
92        assert false;
93    }
94
95    try {
96        let result = DOUBLE_ONE / INT_ZERO;
97    } catch (error: ArithmeticException) {
98        assert false;
99    }
100
101    try {
102        let result : double = DOUBLE_ONE % DOUBLE_ZERO;
103    } catch (error: ArithmeticException) {
104        assert false;
105    }
106
107    try {
108        let result = INT_ONE % DOUBLE_ZERO;
109    } catch (error: ArithmeticException) {
110        assert false;
111    }
112
113    try {
114        let result = DOUBLE_ONE % INT_ZERO;
115    } catch (error: ArithmeticException) {
116        assert false;
117    }
118}
119