-
Notifications
You must be signed in to change notification settings - Fork 0
/
22-Custom-Exception-Handing.vb
50 lines (43 loc) · 1.48 KB
/
22-Custom-Exception-Handing.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
' Author : Jaydatt Patel
' VB.Net is not case sensitive.
'Syntax:
' Try
' [ tryStatements ]
' [ Exit Try ]
' [ Catch [ exception [ As type ] ] [ When expression ]
' [ catchStatements ]
' [ Exit Try ] ]
' [ Catch ... ]
' [ Finally
' [ FinalStatements ] ]
' End Try
' System.Exception : Handle all errors by perticular exception
' ApplicationException : You can also define your own exception. User-defined exception classes are derived from the ApplicationException class.
Imports System
module CustomExceptionModule
class ageError : inherits ApplicationException
public sub new(age as integer)
Mybase.new(string.format("Age not Valid : {0}",age))
end sub
end class
sub validate(age as integer)
try
if age < 18 then
throw(new ageError(age))
else
console.writeline("Age is Valid.")
end if
catch err as ageError
console.writeline("Exception caught: {0}", err)
finally
console.writeline("Validation Executed......")
end try
end sub
sub main()
console.writeline("-------------------------")
validate(20)
console.writeline("-------------------------")
validate(15)
console.writeline("Program Executed Completely")
end sub
end module