You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Tuesday, July 13th 2010, 11:57am

Example for Throwing and Catching specific Exceptions and Errors in Jabaco

Class CFoo: (only a kind of dummy)

Jabaco Source

1
2
3
4
5
6
7
8
Option Explicit 
Private myvalue As Integer
Public Sub CFoo(aval As Integer)
   myvalue = aval
End Sub
Public Function ToString() As String
   ToString = CStr(myvalue)
End Function


Class CList: (attention something happens there)

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Option Explicit
Dim myList() As CFoo
Dim Count As Integer
Public Sub Add(obj As CFoo)
   Redim Preserve myList(0 To Count)
   myList(Count) = obj
   Count = Count + 1
End Sub
Public Function getItem(Index As Integer) As CFoo
   If Index >= Count Then
      Throw New IndexOutOfBoundsException("always look on the bright side of life!")
   Else
      getItem = myList(Index)
   End If
End Function




in the Form with one button you do the follwing:

Jabaco Source

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
Option Explicit
Dim myList As CList
Public Sub Form_Load()
   myList = New CList
End Sub

Public Sub Command1_Click()
   
   Dim f As CFoo
   
   f = New CFoo(123)
   myList.Add f
   
   f = New CFoo(456)
   myList.Add f
Try: On Error Goto Catch
   'Attention here may occur an error :))
   
   f = myList.getItem(3)
   
   Exit Sub
   
Catch:
   If IsClass(Err, IndexOutOfBoundsException) Then
      Dim e As IndexOutOfBoundsException = Cast(Err, IndexOutOfBoundsException) 
      MsgBox e.getMessage
   Else
      MsgBox "nö"
   End If
   
End Sub


create some stop-points in the line "f = myList.getItem(3)" and below "Catch:"

Jabaco also stops in the line where you throw the IndexOutOfBoundsException but also jumps into your ErrorHandler.



regards

OlimilO

Rate this thread
WoltLab Burning Board