public class Math {
public static int divide(int a, int b) {
try {
int result = a / b;
return result;
} catch (ArithmeticException ae) {
System.out.println("Error! Divided by zero!");
} finally {
return 0;
}
}
public static void main(String[] args) {
int result = Math.divide(10, 2);
System.out.println("result = " + result);
}
}
答案 0 :(得分:2)
答案将为零,如@Stephen建议的here所述。
但是我认为您正在尝试解决它。就像有例外一样,则返回0 ;我建议两种方法
第一个带有Set results = html.getElementsByClassName("lemon--div__373c0__1mboc largerScrollablePhotos__373c0__3FEIJ arrange__373c0__UHqhV border-color--default__373c0__2oFDT")
Debug.Print results.Length
Dim output(), r As Long
ReDim output(1 To results.Length, 1 To 3)
r = 1
For i = 0 To results.Length - 1
'On Error Resume Next
html2.body.innerHTML = results.Item(i).innerHTML
output(r, 1) = html2.getElementsByClassName("lemon--a__373c0__IEZFH link__373c0__29943 link-color--blue-dark__373c0__1mhJo link-size--inherit__373c0__2JXk5")(0).innerText
output(r, 2) = html2.getElementsByClassName("lemon--p__373c0__3Qnnj text__373c0__2pB8f text-color--normal__373c0__K_MKN text-align--right__373c0__3ARv7")(0).innerText
output(r, 3) = html2.getElementsByClassName("lemon--p__373c0__3Qnnj text__373c0__2pB8f text-color--normal__373c0__K_MKN text-align--right__373c0__3ARv7")(1).innerText
'On Error GoTo 0
r = r + 1
Next
ws.Cells(GetLastRow(ws, 1) + 1, 1).Resize(UBound(output, 1), UBound(output, 2)) = output
块的方法(也许它最适合您);
finally
第二个没有public static int divide(int a, int b) {
int result = 0;
try{
result = a / b;
return result;
}
catch (ArithmeticException ae) {
System.out.println("Error! Divided by zero!");
}finally {
return result;
}
}
块的
finally
我认为这些可以帮助您