B4J Question Stop logging Java Error messages

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to work out how to stop the Java error messages from displaying when an error occurs, but can't work it out.

I am using the code as shown in the image below and when it runs it should be connecting to a TCP/IP device.

In my example it is trying to connect to 192.168.0.252 on port 1234.

As you can see (in the image below) it failed since this device I am connecting to is offline.

When the device is online it works fine (of course).

Since it failed, it logged the Error message but as you can see it also logged the Java error message as shown in red in the log.

Is there a way to stop logging the Java error as shown in red ? (this happens in debug as well as in release mode.)

I am using B4J version 4.50.

I have also noticed that the astream_Error and astream_Terminated subs never trigger.


upload_2016-10-25_11-3-12.png
 

jmon

Well-Known Member
Licensed User
Longtime User
On my application I just catch the error with Try/Catch (in the connect sub):

B4X:
Sub Process_Globals
    Private RECONNECT As Timer

    'Consts:
    Private Const RECONNECT_TIME As Int = 5000
    Private CONNECT_TIMEOUT As Int = 2500
    Private NET_PORT As Int = 1234
    Public NET_SERVER As String = "192.168.0.252"
    Public CONNECTED As Boolean = False

    'Connections:
    Public so As Socket
    Private astream As AsyncStreams

End Sub

Sub Initialize
    RECONNECT.Initialize("Reconnect", RECONNECT_TIME)
    RECONNECT.Enabled = False
    Connect
End Sub

Sub Connect
    Try
        so.Connect(NET_SERVER, NET_PORT, CONNECT_TIMEOUT)
    Catch
        If LastException.IsInitialized Then
            Log("#Connect failed: " & LastException.Message)
        End If
        setConnected(False)                 
    End Try
End Sub

Public Sub setConnected(Status As Boolean)
    CONNECTED = Status
    If CONNECTED = False Then
        RECONNECT.Enabled = True 'Try to reconnect
    Else
        RECONNECT.Enabled = False 'stop reconnect
    End If
End Sub

Private Sub Reconnect_Tick
    CallSubDelayed(Me, "Connect")
End Sub

Private Sub so_Connected(Successful As Boolean)
    If Successful Then
        If so.CONNECTED Then
            Log("#Connected")
            setConnected(True)
            astream.Initialize(so.InputStream, so.OutputStream, "astream")
        Else
            Log("#Connect failed: Socket not connected.")
            setConnected(False)
        End If
    Else
        LogDebug("#Connect failed")
        setConnected(False)
    End If
End Sub

With this code, if the connection drops, it will try to reconnect. The error will be caught and not displayed in red.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I have also noticed that the astream_Error and astream_Terminated subs never trigger.
They are not raised because it failed to create a connection. They will be raised when an active connection gets broken.

For now you cannot remove this error as it is printed from inside the library, without disabling the logs completely.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Any ETA on when the lib can be updated so it doesn't display this java error ?

Maybe a debug = true/false can be added so it shows/hides these java errors ?
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Why are the logs so critical?
I am developing software for a customer which I am using B4J for, and when they see these Java errors they are going to think the software is faulty and buggy.

If these errors could go to a sub like so_timeout or astram_timeout then I could capture these and not log it and do something with it.

Currently the error messages look like something has failed and they think it's my B4J app where in fact it's nothing major.
 
Upvote 0
Top