I'm just migrating to OOo basic from VB6 and VBA. I can't find an explanation of how to raise errors. For example, suppose I have some code like the example below, how do generate an error from within the "do something" block?
Apologies if there's a more elegant method for error handling that I've not discovered yet. Please feel free to enlighten me.
OK, I have never used VB6 or VBA. You may be able to define an error in either but AFAIK you can't in OOo Basic. It does have an Error() function that will raise an internal error by its error number.
Would you give an example of what you might want to define as an error.
OK, suppose I want to extend the defined set of run-time errors with a new one that I want to handle in a different way. What I'd expect to find is something that tells me what error codes I can use (the predefined ones are listed in Error Function [Runtime] in the programming help) and for there to be a statement or method along the lines of:
Err.Raise number, source, description
This would generate an error in the same way any other run-time error would, and I could then handle the error at the appropriate level. This is the way VBA does it, and I'm not claiming it's that great, but it's frustrating not to be able to find an alternative.
I think a workaround: Err is Global, why not define globals variable Global globNumber%, Global globDescription$, and before you call 'Dim b as Trash' define that globals, than you can read it in all position in your code in the error handler.
Thank you JeJe, I have forgotten CVErr , also Pitonyak says "Use CVErr (as mentioned in Table 23) to create an OOo specific internal data type that represents an error. I have never seen this done".
The problem is CVErr create an type error, but doesn't raise the exception. If you don't raise exception, you don't go to the error handler and so it is not useful to came back. Do you know how raise exceprion with CVErr?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Thank you very much JeJe and Villeroy, very clear example.
I don't know why, but 5 years ago at the start of writing my 20.000 rows of code of my app Edil_LO, I decided do not use Option Compatible or Option VBASupport 1, and code only with original Basic. Maybe I thinked that was more reliability. Is it wrong ??
nickGiard - don't know whether the VBA compatible code is any more or less bug ridden in OO or LO than the other code but you can do things like class modules with VBA support enabled which can be very useful.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)