Exception

Friday, December 7, 2007 0 comments
@@@ Exception @@@

3 kelas Exception, yaitu

1. DivideByZeroException
fungsi : untuk menampilkan Exception yang muncul karena pembagian bilangan bulat atau desimal dengan 0 (nol)

syntax :

Sub Main()
Dim a as integer = 3
Dim b as integer = 0
Dim c as integer

Try
c = a /b

Catch exc As DivideByZeroException
Msgbox ("Error : Pembagian dengan nol")

Finally
Application.Exit()

End Try
End Sub


2. FileNotFoundException
fungsi : untuk menampilkan Exception yang muncul karena file yang dipilih / diinginkan tidak ditemukan

Syntax :

Private Sub MultipleExceptions()
Dim lngSize As Long
Dim s As FileStream

Try
s = File.Open(txtFileName.Text, FileMode.Open)
lngSize = s.Length
s.Close()


Catch e As FileNotFoundException
MessageBox.Show("The file you specified can't be found")

End Try
End Sub


3. DirectoryNotFoundException

fungsi : untuk menampilkan Exception yang muncul karena folder yang dipilih / diinginkan tidak ditemukan atau tidak ada
Syntax :

Private Sub MultipleExceptions()
Dim lngSize As Long
Dim s As FileStream

Try
s = File.Open(txtFileName.Text, FileMode.Open)
lngSize = s.Length
s.Close()

Catch e As DirectoryNotFoundException
MessageBox.Show("You specified a folder that doesn't exist or can't be found.")

0 comments:

 

©Copyright 2011 Ferdian Software | TNB