You are not logged in.

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

1

Wednesday, January 13th 2010, 9:03pm

JABACO Error/Exception Management

Hi Community,

Does any one know how to manage error manage in Jabaco or woring with exceotion errors?
The idea is to catch the error/exception and take action on it e.g database server not started causes a erro like this:

java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused: connect


how would you be able to use this in code? If I use vbError i get a code of 10? What does 10 mean is it a exception error or a "could not connect" error?
I am ROOT if you see me laughing you better have a backup! :cursing:

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

2

Thursday, January 14th 2010, 4:45pm

*bump*
I am ROOT if you see me laughing you better have a backup! :cursing:

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

3

Thursday, January 14th 2010, 5:32pm

Jabaco offers the "on error" mechanism known from VB6.
But my experiences so far are not 100% positive.

Example:

Jabaco code

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
Public Sub Command1_Click()
   Dim i As Integer
   
   On Error Goto ErrHandler
   
   i = 1
   i = i \ (i - i)
   
   Exit Sub
   
ErrHandler:
   MsgBox "got me!"
End Sub


compiles to Java runtime code:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void Command1_Click()
    {
        Throwable Err;
        Err = null;
        int i = 0;
        int i = 1;
        i = (int)((long)i / (long)(i - i));
          goto _L1
_L2:
        Interaction.MsgBox("got me!");
_L1:
        return;
        Err;
          goto _L2
    }


I do not really understand how, but the division by zero exception is handled correctly here.
Jabaco probably defines some entries in the Java exception table of method Command1_Click so that the executing Java Virtual Machine
knows where to jump in case of an exception. This is done so cleverly that it leaves my decompiler behind.

try { } catch { } is not supported.

To find out the meaning of a certain return code, you have several options:
- read the documentation
- examine samples of others
- search the source code (of the Jabaco framework)
- dissect Jabaco.jar using a Java decompiler like jad or jd-gui

The decompiler reveals that Jabaco's error handling is not always perfect.

Greetings!

A1880

This post has been edited 2 times, last edit by "A1880" (Jan 14th 2010, 10:41pm)


  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

4

Thursday, January 14th 2010, 7:33pm

thx A1880!

I googled the planet last night. I also tried the catch { } thing. Now at least I know!
thank you for the reply.

Riaan

:D
I am ROOT if you see me laughing you better have a backup! :cursing:

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

5

Thursday, January 14th 2010, 8:46pm

I had a look at the source and found this;

vbError = 10

public VBVariant(Exception e) { setVal(e); } //iTyp = 10


so there is my error code. Very generic, not going to be easy to build error management routines.
For example I forgot to start my MySQL and this error:

Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused: connect

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
at com.mysql.jdbc.Connection.<init>(Connection.java:452)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Global.testdatabase(Global.jsrc:18)
at frmLogin.Command1_Click(frmLogin.jsrc:8)
at frmLogin$CommandButton._Click(frmLogin.jsrc:9)
at VB.CommandButton.actionPerformed(CommandButton.jsrc)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at VBA.JabacoEventQueque.dispatchEvent(JabacoEventQueque.java:20)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


** END NESTED EXCEPTION **


so in short the exception above is Error 10.

R
I am ROOT if you see me laughing you better have a backup! :cursing:

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

6

Thursday, January 14th 2010, 9:48pm

You could try and activate some logging either on the client side (jdbc logging) or on the server side (MySQL logging).
"Connection refused" sounds like a firewall, router or networking problem. The server might not even be running at all ;-)
Can you reach the server with netcat or some other application to make sure connectivity is OK?

Try reaching your MySQL server with the MySQL client. Make sure that you enter the correct TCP/IP port number in the connect string.
Another pitfall might be that the MySQL server has to be instructed to accept connections from the given client host.
Finally, make sure that the hostname in your connect string is properly resolved by your DNS.
In case you are connecting locally, try "127.0.0.1" instead of "localhost".

Success!

A1880

This post has been edited 1 times, last edit by "A1880" (Jan 14th 2010, 10:04pm)


  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

7

Friday, January 15th 2010, 8:38am

Previous Post .... For example I forgot to start my MySQL and this error: ...

These things happen every know and then. That is how I discovered that Java has the weirdest error handling.

In the most perfect conditions your application will always work with no problems. You SQL server will always be online, your printer will never run out of paper, and your network will never fail.... (sarcasm) LOL

I am thinking of using the err.string and using the message to build up a error lib?

This is pretty much self explanatory ------> MESSAGE: java.net.ConnectException: Connection refused: connect
And I know what class it was using ------> com.mysql.jdbc.Connection

I could process that text and save in a error library of sorts?

I have to keep in mind that a ordinary user would not understand a logging system. And it would make supporting it a nightmare. It is always easier if the application itself can pretty much "fix itself". I used to do this in VB6.

For example error flow chart to explain:

in VB6 the ADO conection fails ---- VB informs the user that there is no DB connection would he like to retry or wait 5 min? ---> User selects 5 Min ----> System tries again and finds the network to be back online and connects to DB serverf --- USER HAPPY!


In JAVA ----> Database Offline ---> Exeception Error ---> CRASHES!!!!!! ----> User going WTF??????? ----> has to restart App and lost all entered data....


See what I mean? Think my error lib will work? I could always (once it works well) give it back to Jabaco Devel guys to maybe use and implement?

Riaan
I am ROOT if you see me laughing you better have a backup! :cursing:

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

8

Friday, January 15th 2010, 9:59am

OK. You are right. Software should behave as transparently and self-curing as possible.
Over the years, I've learned to appreciate the value of defensive programming.
It pays off in many situations to check pre-conditions and post-conditions in a method or routine.

To be able to react on errors you have to catch them first.
It is therefore vital to have a correct implementation of "ON ERROR" or "try {} catch {}".
You could help improving Jabaco by testing this and reporting deficiencies.

My previous postings aimed at helping you to get your MySQL connection working.
Logging is mostly good for developers and not for normal end users.
The motto is: First make it run and than make it faster/nicer/saver ....

Greetings

A1880

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

9

Friday, January 15th 2010, 9:40pm

Persistence pays off....

This is what I will be using for the time being until there is a better method or new stuff gets added to Jabaco.


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
Public Function JabacoErrorManager (MyError As String, MyAction As String, FullErrorMessage As String) 
'Dim variables to use
Dim AddEnter As String 

'Print To Console for Debug
Debug().Print(MyError)

'Line Feed
AddEnter = Chr(10)

'This is how we will handle the error

  	Select Case MyError
     	'Java Sql Exception
     	Case "java.sql.SQLException": MsgBox "Error:   "  & MyError & AddEnter & "Action:   " & MyAction & AddEnter & "Fix:   " & "Confirm the database server is online and try again, System will Exit now", vbOKOnly, "Critical System Error"
                                   	System.exit 0

     	Case "java.lang.ArithmeticException": MsgBox "Error:   "  & MyError & AddEnter & "Action:   " & MyAction & AddEnter & "Fix:   " & "Confirm that there is no division by zero exception", vbOKOnly, "Critical System Error"

     	Case Else
           	
           	MsgBox "Error:   "  & MyError & AddEnter & "Action:   " & "Unknown" & AddEnter & "Fix:   " & "None" & AddEnter & AddEnter & "Full Debug Information: " & FullErrorMessage , vbOKOnly, "Critical System Error"
    	End Select  


End Function



and it is used like this in code:


Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
Public Sub Command1_Click()
   Dim i As Integer
On Error Goto ErrHandler

  i = 1
   i = i \ (i - i)



ErrHandler:
JabacoErrorManager (Err.getClass.getName, "While Connecting to MySQL Server",Err.getMessage)
End Sub



Not perfect I know.. But works WAY better then the java error stuf! so far... LOL


Riaan
I am ROOT if you see me laughing you better have a backup! :cursing:

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

10

Friday, January 15th 2010, 9:43pm

oh and PLEASE criticise, flame, comment and suggest! Always nice to know what other think 8)
I am ROOT if you see me laughing you better have a backup! :cursing:

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

11

Friday, January 15th 2010, 11:17pm

Just for your inspirantion an example with nested exception/error handling:

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
32
33
34
35
36
Option Explicit

Public Sub Command1_Click()
   Dim i As Integer
   
   On Error Goto ErrHandler
   
   Call f1
   
   Debug.Print "click: back again!"
   Exit Sub
   
ErrHandler:
   MsgBox "click: " & Err.getMessage
   
End Sub


Private Sub f1
   Dim i As Integer
   
   On Error Resume Next
   i = i \ (i - i)
   
   If Err <> Null Then
      Debug.Print "f1: '" & Err.getMessage & "'"

      '  switch on exception handling
      On Error Goto 0

      ' back To error handler one calling layer above
      Throw New Exception("something went wrong! " & Err.getMessage & vbcrlf & "(" & Err.toString & ")")
   Else
      Debug.Print "f1: alright!"
   End If
End Sub


The cool feature is that you can bump out from the innermost routine to the outer ErrorHandler lable.
This is far more flexible than finishing off the whole application at the first error.
Well done, Manuel!

Greetings

A1880

  • "Riaan Pretorius" is male
  • "Riaan Pretorius" started this thread

Posts: 21

Date of registration: Nov 14th 2009

Location: Krugersdorp, South Africa

Occupation: Linux Opensource Consultant

Hobbies: Programming

  • Send private message

12

Friday, January 15th 2010, 11:53pm

Great Stuff! I will modify on my side :)
I am ROOT if you see me laughing you better have a backup! :cursing:

giucleand

Beginner

  • "giucleand" is male

Posts: 11

Date of registration: Oct 27th 2009

Location: Romania

Occupation: sysadmin

  • Send private message

13

Tuesday, February 2nd 2010, 11:03am

Unexpected unhandled exception

Please tell me what am I doing wrong here:
Public Sub Command1_Click()

On Error Goto ErrHandler
Dim XmyFile As VBFileHandler
'the file location does not exist, in order to trigger the error
XmyFile = Open("w:\com0\valutar\last.nfo", Random, Write, Shared)

Exit Sub

ErrHandler:
MsgBox "Error occured"
End Sub


All I get is the "Unhandled exception..." message (see the screenshot)

Thanks for your help!

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

14

Thursday, February 11th 2010, 1:11pm

Please have a look at this related post

Greetings

A1880

giucleand

Beginner

  • "giucleand" is male

Posts: 11

Date of registration: Oct 27th 2009

Location: Romania

Occupation: sysadmin

  • Send private message

15

Friday, February 12th 2010, 4:31pm

Javam quotidianum ...

Thanks a lot! It seems that a glimpse of Java might be real necessary. So be it then.

  • "WhatIsSoftware" is male

Posts: 21

Date of registration: Apr 28th 2012

Location: CyberVillage

Hobbies: Web Development. Android Development. Jabaco Development. :)

  • Send private message

16

Thursday, June 14th 2012, 5:38am

Doesn't understand why Java has to be so difficult about error handling :thumbdown:

Rate this thread
WoltLab Burning Board