You are not logged in.

tunleader

Beginner

  • "tunleader" is male
  • "tunleader" started this thread

Posts: 5

Date of registration: Mar 21st 2011

Location: Tunisia

Occupation: Developper

  • Send private message

1

Tuesday, March 22nd 2011, 7:28pm

Exceptions

Hi,
I'm a java programmer and I'm new with Jabaco, could someone tell me how to handle Java Exceptions with Jabaco ...
thx in advance

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Tuesday, March 22nd 2011, 10:41pm

Here is a simple example:

The Jabaco code

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Option Explicit

Public Sub Command1_Click()
   Dim tb As TextBox = Null
   
   On Error Goto ErrHandler
   
   '  the following line provokes a nullpointer exception
   
   tb.Text = "a text"
   
   Exit Sub
   
ErrHandler:
   MsgBox "got it wrong!"
End Sub


The de-compiled Java code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Couldn't fully decompile method Command1_Click
Couldn't resolve all exception handlers in method Command1_Click
    public void Command1_Click()
    {
        Throwable Err;
        TextBox tb;
        Err = null;
        tb = null;
        tb.$Text("a text");
          goto _L1
_L2:
        Interaction.MsgBox("got it wrong!");
_L1:
        return;
        Err;
          goto _L2
    }


The de-compiled Java byte code:

Source code

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
 public void Command1_Click()
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aconst_null
    //   3: astore_3
    //   4: aload_3
    //   5: ldc 211
    //   7: invokevirtual 216	VB/TextBox:$Text	(Ljava/lang/String;)V
    //   10: goto +10 -> 20
    //   13: nop
    //   14: ldc 218
    //   16: invokestatic 224	VBA/Interaction:MsgBox	(Ljava/lang/String;)LVBA/VBMsgBoxResult;
    //   19: pop
    //   20: nop
    //   21: return
    //   22: astore_2
    //   23: astore_1
    //   24: ret 2
    //   26: jsr -4 -> 22
    //   29: goto -16 -> 13
    //
    // Exception table:
    //   from	to	target	type
    //   4	20	26	finally
  }


Jabaco is using the "on error" mechanism known from VisualBasic 6 rather than the try() / catch() from Java.
It should be possible to catch all exceptions using an "on error" statement.

Happy experimenting!

A1880

tunleader

Beginner

  • "tunleader" is male
  • "tunleader" started this thread

Posts: 5

Date of registration: Mar 21st 2011

Location: Tunisia

Occupation: Developper

  • Send private message

3

Wednesday, March 23rd 2011, 1:47pm

Thx, I'll try it ... :)

Rate this thread
WoltLab Burning Board