Hi,

I'm wondering why is there no "Index Out Of Range" when using the built-in function Substr()?

Example:

Substr("AAA", 5, 11) = "A" ? FALSE (Empty String = "A")
Substr("AAA", 5, 11) = "" ? TRUE (Empty String = Empty String)

I thought that this error is built-in but there isn't.
Why does OutSystems allow such thing?

Hi Loi Hua,

What's the advantage for you of getting an Index Out Of Range exception? You can still get the same information without any errors by checking if the start of the substring is larger than the size of the string... (5 > "AAA".Length)

Solution

Loi Hua wrote:

Hi,

I'm wondering why is there no "Index Out Of Range" when using the built-in function Substr()?

Example:

Substr("AAA", 5, 11) = "A" ? FALSE (Empty String = "A")
Substr("AAA", 5, 11) = "" ? TRUE (Empty String = Empty String)

I thought that this error is built-in but there isn't.
Why does OutSystems allow such thing?

I would say this is done to simplify workflows. If Outsystems had such an exception you'd have to implement much more logic in your code to have all the exception handlers for every single type of exceptions. And considering that exception handler's scope is an action you would need to create a LOT of wrapper actions.

And as Jorge said it's not really that much value in such an exception.


Solution

Hi Jorge Martins, Vitaly Martynenko

Up till yesterday, I still thought that obviously it would raise an exception when the Index is out of range, then I found out that wasn't the case. So I'm just wondering. Thanks for clarifying.