try/catch, switch/case
Comments
-
100% agree - they are coming!
-
I second that emotion!! My use case:
Rather than multiple functions to handle customer data, I'm creating 1 role-based CRUD function to simplify managing future role additions to managing customer data.
One case switch operator and bye bye multiple conditional statements [image.png] -
Any update on this?
-
we have a partial update to this. I would recommend trying out our Lambda support if this is a big concern for your use case. You can 100% use try/catch and switch/case in a Lambda, which hopefully can tie you over until our next iteration of the function stack is released.
-
Yes that worked.
-
2nd this. Case/switch would clean up stack considerably.
-
Can anyone throw in an example of a switch as a lambda, done in Xano? Would appreciate
-
Switch/case is most easily done now as a sequence of if-else conditionals. Since switch is exclusive, you can check for "if x = a then... if x = b then...." as a stack without having to nest them in "else". That's what I usually advise people to do. Using the "return" utility function mixes with this pattern very well too.
Lambdas are more helpful for complicated situations that might require something like a try-catch, since them failing will not crash the current function stack. Another path on that is to connect to an internal-only API endpoint to handle that logic. That way an error on that other endpoint would generate a 500 that your current function stack could check for in the response, but not be crashed by.
-
Thanks, @Ray Deck. Just un-nested a few conditionals. Definitely easier to work this way but I understand there is a tiny bit of extra processing on the function this way, compared to a switch. But that's ok for me.
-
I only understood today there is no Switch, but even more surprising, the If…Else doesn't handle Else if branch.
That's quite surprising, and a real struggle to overcome. "Else if" is more important than doing Switch (IMHO), because it can also be used to handle Switch use-cases.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback