Error is thrown before the error handler can handle it

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
preechaw
Posts: 2
Joined: Mon Apr 22, 2019 6:39 am

Error is thrown before the error handler can handle it

Post by preechaw »

Hi.

I tried to emulate Excel IFERROR function.

I tried to do it in two ways:

[First]

Code: Select all

Function IFERROR(Expression as Variant, DefaultValue as Variant)
	If ISERROR(Expression) Then
		IFERROR = DefaultValue
	Else
		IFERROR = Expression
	End If
End Function
[Second]

Code: Select all

Function IFERROR(Expression as Variant, DefaultValue as Variant)
	On Error Goto ERRHANDLER
	IFERROR = Expression
	Exit Function
ERRHANDLER:
	IFERROR = DefaultValue
End Function
The problem is when the expression is erroneous, it's shown in the cell and the error handling inside the functions doesn't have a chance to handle it.

Is there any way to achieve this?

Thanks.
OpenOffice 4.1.6, Windows 10
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Error is thrown before the error handler can handle it

Post by JeJe »

Have you seen this thread:

viewtopic.php?t=74980&p=340000
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
preechaw
Posts: 2
Joined: Mon Apr 22, 2019 6:39 am

Re: Error is thrown before the error handler can handle it

Post by preechaw »

I realize it can be done that way.
If the workbook contains so many places using IFERROR, it's time-consuming to edit all of them (in case their occurrences are not consecutive and cannot be copied/pasted easily).
Using a VBA function will be more efficient.

Now my concern is not only how to make an equivalence of IFERROR.
It's now how to trap expression errors in the function.
The current behavior is the error is displayed before the function works.
OpenOffice 4.1.6, Windows 10
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Error is thrown before the error handler can handle it

Post by Zizi64 »

I tried to emulate Excel IFERROR function.
The LibreOffice Calc has IFERROR() function, but the Apache OpenOffice Calc has not.

Try it, and use it.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Error is thrown before the error handler can handle it

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply