LO Basic - How to raise an error without VBASupport?

Hi everybody,

I have been struggling for hours with the problem of not knowing how to throw an error without using VBASupport mode. I am using LO 24.2.1.2 on a Mac (Apple Silicon) and here is the code that I want to change (cf. my comments)

Option VBASupport 1                        ' I don't like to use VBA support
Sub RaiseErrorInVBA
    On Local Error GoTo Alert

    Number = 1102                          ' I'd like to define my own errno
    Source = "My Error Source"             ' I'd like to define the source
    Description = "My error description"   ' I'd like to give a description
    
    Err.Raise(Number, Source, Description) ' I'd like to use _pure_ LO Basic
    MsgBox ("Never reach this line")       ' instead of using VBA »Err.Raise«
    Exit Sub
    
Alert:                                     ' I'd like to use Err, Erl, Error$
    MsgBox "Error "& Err &" at line "& Erl &" in "& Err.Source _
          &" as "& Err.Description, MB_ICONEXCLAMATION
End Sub

Can somebody please help me and show me how to do it in »pure LO Basic«?
Thank you very much
Thomas

Welcome to the forum!
The Option VBASupport 1 construction is »pure LO Basic«, it is used not only in the case you described, but also, for example, when creating UDF functions.
You can have a separate module for your function, and use modules without Option VBASupport 1 for other functions.

Thank you @sokol92 for your greeting. Your solution does not work for me, but after another 2h :laughing: I found a workaround that works for me:

Sub DoLikeAnErrorWithoutVBASupport
    On Local Error GoTo Alert

    ' Here and in this module is other code, not compatible with VBASupport 1
    
    ' Uncomment next line to raise a real error and use the same GoTo label
  'Open "/this/file/does/not/exist.file" For Input As #iFno

    ' Here comes the »do like an error« workaround for my initial problem
    Dim Err as Integer  : Err    = 1102            ' Set own error number
    Dim Erl as Integer  : Erl    = 13              ' Set unattractive #lineno
    Dim Error As String : Error$ = "My Error Text" ' Set own error string
    GoTo Alert                                     ' Do instead VBA »Err.Raise«
    
    MsgBox ("Never reach this line of code")       
    
Alert:                                             ' I can use Err, Erl, Error$
    MsgBox "Error " & Err & Chr(10) _              ' for real errors or my ugly
         & "at line " & Erl & Chr (10) _           ' workaround solution
         & "in " & Error, MB_ICONEXCLAMATION
    End                                            ' Stop program execution
End Sub

Have a good day!