B4J Question [Solved] Capture BCTextEngine error text

bdunkleysmith

Active Member
Licensed User
Longtime User
I have an app which includes a text box where the user can edit text which is subsequently displayed as scrolling text.

To ensure the app does not crash if the user uses text tags incorrectly, I have used a Try/Catch:

B4X:
Sub btnTestText_Click
    Try
        lblScroll.Text = txtBBCode.Text
    Catch
        Log(LastException)
        msgBox.Show("Check your text tags", "Error")
    End Try
End Sub

If I purposely delete a tag when I run the code in the IDE, in the logs I see:

Error (position - 47): Closing tag does not match: b
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).

Rather than just show "Check your text tags" in the message box, I would like to enhance feedback to the user by replacing "Check your text tags" with "Error (position - 47): Closing tag does not match: b", but how do I capture that error text, which I presume comes from the BCTextEngine?
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks @Erel; TextEngine.TagParser.ErrorString indeed gives me what I was after and so I incorporated it into my code:

B4X:
Sub btnTestText_Click
    Try
        lblScroll.Text = txtBBCode.Text
    Catch
        Dim error As String = TextEngine.TagParser.ErrorString
        Dim title As String = error.SubString2(0, error.IndexOf(":"))
        Dim msg As String = error.SubString(error.IndexOf(":") + 2)
        Main.msgBox.Show(msg, title)
    End Try
End Sub

However (and perhaps this should be a new thread) if I purposely delete a tag to create an error which displays the message box as expected and then reinsert the tag in the txtBBCode textbox, it continues to throw the error.

It seems like I need to reset or re-initialise the parser, but what is strange is that I have another button which loads the same (corrected) text to another scrolling text instance without error. So I'm unsure how to reset or re-initialise the parser associated with that sub.
 
Upvote 0
Top