Bug? Select statement syntax error produces weird runtime error

Widget

Well-Known Member
Licensed User
Longtime User
I inadvertently mistyped the syntax of a Select statement and got this weird runtime error message that took me a while to hunt down because it gave me the wrong line number.

Here is the error message:
B4A version: 6.80
Parsing code. (0.00s)
Compiling code. (0.04s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.01s)
Generating R file. (0.14s)
Compiling debugger engine code. Error
B4A line: 25
End Sub
javac 1.8.0_121
shell\src\b4a\example\main_subs_0.java:68: error: 'try' without 'catch' or 'finally'
try {
^
1 error


Here is the syntax that caused it:
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub    '<--- Here is line 25 from the runtime error message

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub MySub
    Private locValue As String="A"
   
    Select locValue
        Case "A"
            Log(locValue)
        Case "B"
            Log(locValue)
        Else                       'Should be "Case Else" and not "Else"
            Log("Unknown")
    End Select
End Sub

As you can see, the Select statement had an "Else" clause where it should have been "Case Else". Other languages use "Else" for a Case structure so I fell back to my old ways. It was my mistake, but I would have thought the compiler should have caught it or the syntax checker in the editor should have flagged it as an error. The runtime error flagged line 25 which was no where near MySub() so it took me a while to find the cause of the error.

I just thought I'd mention it in case someone else makes the same typo and perhaps it can be caught by the compiler in a future version. No rush on my part because when I bang my thumb with a hammer I usually try not to repeat the mistake (or at least persuade someone else to hold the nail!). :eek:

TIA
 
Top