这里定义了一个错误的激发条件 (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
|
阅读(366) | 评论(0) | 转发(0) |