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.
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.
If nothing is done, how are we supposed to know the value wasnāt found?
try
pm.SelectRowWithValue("NonExistant")
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ā¦
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.
Maybe for your case an extension method could help.
I made a project for you to play with
PopupMenu Extends.xojo_xml_project 30kb