类型' System.OverflowException'的未处理异常Visual Basic WPF

时间:2018-03-31 13:01:04

标签: wpf vb.net visual-studio-2015

什么是System.OverflowException?

[dev]
JDBC_URL = jdbc:h2:mem:mem_test;MODE=Oracle
JDBC_USERNAME =
JDBC_PASSWORD =

SERVICE_ENDPOINT = http://localhost:8080/Central/api/AppService

[qa]
JDBC_URL = jdbc:oracle:thin:@qa-oracle:1521:qa
JDBC_USERNAME = qauser
JDBC_PASSWORD = qapass

SERVICE_ENDPOINT = http://qa-services/Central/api/AppService

[prod]
JDBC_URL = jdbc:oracle:thin:@prod-oracle:1521:prod
JDBC_USERNAME = scott
JDBC_PASSWORD = tiger

SERVICE_ENDPOINT = http://prod-services/Central/api/AppService

我使用Long,我需要使用ULong吗?

1 个答案:

答案 0 :(得分:0)

你需要在此周围放置一个Try / Catch,这不是一个安全的子程序。添加和乘法很容易抛出OverflowException。

当您尝试将结果分配给无法处理大量金额的数据类型时,可能会发生溢出:https://msdn.microsoft.com/en-us/library/system.overflowexception(v=vs.110).aspx

例如,像这样的东西会抛出OverFlow:

Dim intType As Integer = Convert.ToInt32(Long.MaxValue)

我可能会建议尝试更安全的东西:

Private Sub buttonSD_Click(sender As Object, e As RoutedEventArgs) Handles buttonSD.Click
    Try
        AngkaPertama = textBox1.Text
        AngkaKedua = textBox2.Text

        If Kalkulasi = "+" Then
            Hasil = AngkaPertama + AngkaKedua
        ElseIf Kalkulasi = "-" Then
            Hasil = AngkaPertama - AngkaKedua
        ElseIf Kalkulasi = "*" Then
            Hasil = AngkaPertama * AngkaKedua
        ElseIf Kalkulasi = "/" Then
            Hasil = AngkaPertama / AngkaKedua
        End If

        textBoxHasil.Text = Hasil
    Catch sofEx As OverflowException
        'put error in result box, or log it, or something
        textBoxHasil.Text = "Error: result too large"
    Catch ex As Exception
        'some other exception
        textBoxHasil.Text = ex.Message
    End Try
End Sub