module1.vb

来自「编程之道VB.NETt程序设计入门-589M.zip」· VB 代码 · 共 51 行

VB
51
字号
Module Module1

    Sub Main()
        Dim i, j, k As Integer
        Dim s, t As String

        Console.WriteLine("请输入一个除数")
        s = Console.ReadLine()
        Try
            i = Integer.Parse(s)
        Catch e As ArgumentNullException
            Console.WriteLine("您没有输入")
        Catch e As FormatException
            Console.WriteLine("您没有输入一个有效的整数")
        Catch e As OverflowException
            Console.WriteLine("您输入的数字过大或过小")
        End Try

        Console.WriteLine("请输入被除数")
        t = Console.ReadLine()
        Try
            j = Integer.Parse(t)
        Catch e As ArgumentNullException
            Console.WriteLine("您没有输入")
        Catch e As FormatException
            Console.WriteLine("您没有输入一个有效的整数")
        Catch e As OverflowException
            Console.WriteLine("您输入的数字过大或过小")
        End Try

        Try
            k = i / j
            Throw New Exception("自定义的异常")
        Catch e As OverflowException
            If j = 0 Then
                Console.WriteLine("被除数为0!")
            Else
                Console.WriteLine("运算发生溢出")
            End If
        Catch e As Exception
            Console.WriteLine(e.Source & " " & e.Message)
        Finally
            Console.WriteLine(k)
        End Try

        Console.ReadLine()

    End Sub

End Module

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?