SelectRowWithValue -> exception

When using .SelectRowWithValue (DesktopPopupmenu) and the value is not found, an exception is thrown.

Imo it would be better to not throw an exception and just do nothing instead.
Now you need to handle that exception which is a bit overkill.

1 Like

If nothing is done, how are we supposed to know the value wasn’t found?


catch ex as KeyNotFoundException
end try

Written in post editor just for you.

I’d say return a boolean, and use call when you want to ignore it. Exceptions make this a bit slow but hey you could just write your own extiontion function…

1 Like

100% agree. Imo exceptions should be reserved for things the runtime engine truly cannot resolve like NilObject and OutOfBounds. For “usage” errors, return values or error codes make for much more concise code, uncluttered by verbose Try-Catch syntax.

For example, IndexOf returns -1 if the search string isn’t found, not an exception, which would be nightmarish.


Yes, the exception is endlessly annoying in this case. I have pulled some hairs with this already.

Does Xojo Inc read this here? Or do I need to add a ‘bug ticket’?

Nothing or maybe return -1

I have about 200 popupmenu controls that I need to set by using text.
So that would mean I have to add a try/catch for each. That’s not really workable.

In the mean time I have added my own code that does the job. But nevertheless throwing an exception for SelectRowWithValue is not good practice imo. It should return for example -1
As Julia wrote, IndexOf also doesn’t use an exception. That would equally be silly to do.

1 Like

Maybe for your case an extension method could help.

I made a project for you to play with :slight_smile:
PopupMenu Extends.xojo_xml_project 30kb

1 Like