What?
A really quick article on demonstrating a nested try...catch()... statement working in Zoho CRM.
Why?
To prove a point to ChatGPT who said this was not possible... and to deal with a scenario which exists for a client of mine.
The use-case for my Cx is that they need documents converted from HTML to PDF — as in we send it a bit of code in HTML and we want a PDF file returned. I have severaly instances of an API which accepts HTML and returns a PDF file. Nothing complex but issues with one of the servers being down, or inaccessible due to certificate expirys, means that the Cx business halts. In order to add a bit of clustering, we have added a bit of code for it to try one server first, if there is any kind of an error with that server, it tries a second server... We now want to add a third server to try if the first 2 fail for whatever reason.
How?
Admittedly, perhaps this maybe wasn't possible but as of February 2024; I have been able to test and implement this.
Consider the following code:
try { v_Test1 = "Foo"; info v_Test1.toLong(); } catch(e) { info "Couldn't convert 'Foo' to an integer"; try { v_Test2 = "Bar"; info v_Test2.toLong(); } catch(e) { info "Couldn't convert 'Bar' to an integer"; } }
- try
- {
- v_Test1 = "Foo";
- info v_Test1.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Foo' to an integer";
- try
- {
- v_Test2 = "Bar";
- info v_Test2.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Bar' to an integer";
- }
- }
Pushing the product beyond it's design
Note that before anyone says I'm only try catching a doomed conversion from string to integer; I've applied this to an actual invokeURL command rather than just an info output.
try { r_GeneratePDF = invokeurl [ url: v_EndpointServer1 type: POST parameters: m_Html headers: m_Headers1 ]; } catch(e) { try { r_GeneratePDF = invokeurl [ url: v_EndpointServer2 type: POST parameters: m_Html headers: m_Headers2 ]; } catch(e) { r_GeneratePDF = invokeurl [ url: v_EndpointServer3 type: POST parameters: m_Html headers: m_Headers3 ]; } }
- try
- {
- r_GeneratePDF = invokeUrl
- [
- url: v_EndpointServer1
- type: POST
- parameters: m_Html
- headers: m_Headers1
- ];
- }
- catch(e)
- {
- try
- {
- r_GeneratePDF = invokeUrl
- [
- url: v_EndpointServer2
- type: POST
- parameters: m_Html
- headers: m_Headers2
- ];
- }
- catch(e)
- {
- r_GeneratePDF = invokeUrl
- [
- url: v_EndpointServer3
- type: POST
- parameters: m_Html
- headers: m_Headers3
- ];
- }
- }
This feels like really bad practice
try { v_Test1 = "Foo"; info v_Test1.toLong(); } catch(e) { info "Couldn't convert 'Foo' to an integer"; try { v_Test2 = "Bar"; info v_Test2.toLong(); } catch(e) { info "Couldn't convert 'Bar' to an integer"; try { v_Test3 = "Everyday I'm Nesting..."; info v_Test3.toLong(); } catch(e) { info "Couldn't convert 'Everyday...' to an integer"; try { v_Test4 = "Another for the road..."; info v_Test4.toLong(); } catch(e) { info "Couldn't convert 'Another...' to an integer"; } } } } // yields: // "Couldn't convert 'Foo' to an integer" // "Couldn't convert 'Bar' to an integer" // "Couldn't convert 'Everyday...' to an integer" // "Couldn't convert 'Another...' to an integer"
- try
- {
- v_Test1 = "Foo";
- info v_Test1.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Foo' to an integer";
- try
- {
- v_Test2 = "Bar";
- info v_Test2.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Bar' to an integer";
- try
- {
- v_Test3 = "Everyday I'm Nesting...";
- info v_Test3.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Everyday...' to an integer";
- try
- {
- v_Test4 = "Another for the road...";
- info v_Test4.toLong();
- }
- catch(e)
- {
- info "Couldn't convert 'Another...' to an integer";
- }
- }
- }
- }
- // yields:
- // "Couldn't convert 'Foo' to an integer"
- // "Couldn't convert 'Bar' to an integer"
- // "Couldn't convert 'Everyday...' to an integer"
- // "Couldn't convert 'Another...' to an integer"
Add comment