A more useful Exception object.
With this library you can create your own Exception object, continuing to benefit from the one offered by B4A.
Other advantages:
1) lmException has ExtraData, see @Ed Brown' suggestion, post #2.
and HasExtra (same as Intents).
2) B4A Exception message can be only in English, with lmException you can localize this message.
How and why to use it - an example:
If you had this code, using the B4A Exception:
With B4A Exception, you can not create an exception as you would need in this case, like "Invalid name".
With lmException, you can write:
As usual, you should copy the two files, lmException.jar and lmException.xml, to your "additional libraries path".
With this library you can create your own Exception object, continuing to benefit from the one offered by B4A.
Other advantages:
1) lmException has ExtraData, see @Ed Brown' suggestion, post #2.
and HasExtra (same as Intents).
2) B4A Exception message can be only in English, with lmException you can localize this message.
How and why to use it - an example:
If you had this code, using the B4A Exception:
B4X:
Public Sub Something
Dim ex As Exception : ex = Null
ex = LoadData
If ex.IsInitialized Then
Msgbox(ex.Message, "Loading data")
Else
' do something
End If
End Sub
Private Sub LoadData As Exception
Dim ex As Exception : ex = Null
Try
Dim Cur As Cursor
Cur = DB.ExecQuery("SELECT * FROM MyTable")
If Cur.IsInitialized And Cur.RowCount > 0 Then
Cur.Position = 0
Dim Name As String = Cur.GetString("Name")
If Name = "Luca" Then
' Raise an exception, Luca should be "Mario"
End if
End if
'...
Catch
ex = LastException
End Try
Return ex
End Sub
With lmException, you can write:
B4X:
Public Sub Something
Dim ex As lmException : ex.Initialize
ex = LoadData
If ex.Raised Then
Msgbox(ex.Message, "Loading data")
Else
' do something
End If
End Sub
Private Sub LoadData As lmException
Dim ex As lmException : ex.Initialize
Try
Dim Cur As Cursor
Cur = DB.ExecQuery("SELECT * FROM MyTable")
If Cur.IsInitialized And Cur.RowCount > 0 Then
Cur.Position = 0
Dim Name As String = Cur.GetString("Name")
If Name = "Luca" Then
ex.Message = "Luca should be Mario"
' or: ex.Message = "Luca dovrebbe essere Mario"
End if
End if
'...
Catch
ex.Message = LastException.Message
End Try
Return ex
End Sub
As usual, you should copy the two files, lmException.jar and lmException.xml, to your "additional libraries path".
Attachments
Last edited: