Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188398
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类:

2010-04-27 14:04:40

这里定义了一个错误的激发条件 (month < 1 Or month > 12) ,     然后用Throw New ArgumentOutOfRangeException()抛出一个异常,再通过Try中的 Catch e As ArgumentOutOfRangeException接收异常提示并做出反应。

代码如下:

 

Module Module1

    Sub Main()
        Dim month As Integer
        Do While (True)
            Try
                KeyinMonth(month)
                Exit Do
            Catch e As ArgumentOutOfRangeException
                Console.WriteLine("乐博网提示:不合理月份")
            Catch e As Exception
                Console.WriteLine("乐博网提示:其它种错误")
            End Try
        Loop
        Console.ReadLine()
    End Sub

    Public Sub KeyinMonth(ByRef month As Integer)
        Console.Write("乐博网提示:输入月份 ( 1 - 12 ) : ")
        month = Console.ReadLine()
        If (month < 1 Or month > 12) Then
            Throw New ArgumentOutOfRangeException()
        End If
    End Sub

End Module


阅读(310) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~