Error is thrown before the error handler can handle it

Creating a macro - Writing a Script - Using the API

Error is thrown before the error handler can handle it

Postby preechaw » Mon Apr 22, 2019 6:50 am

Hi.

I tried to emulate Excel IFERROR function.

I tried to do it in two ways:

[First]
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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
preechaw
 
Posts: 2
Joined: Mon Apr 22, 2019 6:39 am

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

Postby JeJe » Mon Apr 22, 2019 8:47 am

Have you seen this thread:

viewtopic.php?t=74980&p=340000
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 507
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby preechaw » Mon Apr 22, 2019 8:53 am

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
preechaw
 
Posts: 2
Joined: Mon Apr 22, 2019 6:39 am

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

Postby Zizi64 » Mon Apr 22, 2019 10:12 am

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; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby JeJe » Mon Apr 22, 2019 1:07 pm

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 507
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests