Zoho Deluge: Nested Catch Statements

Zoho Deluge: Nested Catch Statements

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:

copyraw
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";
			
		}
	}
  1.  try 
  2.      { 
  3.          v_Test1 = "Foo"
  4.          info v_Test1.toLong()
  5.      } 
  6.      catch(e) 
  7.      { 
  8.          info "Couldn't convert 'Foo' to an integer"
  9.          try 
  10.          { 
  11.              v_Test2 = "Bar"
  12.              info v_Test2.toLong()
  13.   
  14.          } 
  15.          catch(e) 
  16.          { 
  17.              info "Couldn't convert 'Bar' to an integer"
  18.   
  19.          } 
  20.      } 

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.

copyraw
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
			];
		}
	}
  1.  try 
  2.      { 
  3.          r_GeneratePDF = invokeUrl 
  4.          [ 
  5.              url: v_EndpointServer1 
  6.              type: POST 
  7.              parameters: m_Html 
  8.              headers: m_Headers1 
  9.          ]
  10.      } 
  11.      catch(e) 
  12.      { 
  13.          try 
  14.          { 
  15.              r_GeneratePDF = invokeUrl 
  16.              [ 
  17.                  url: v_EndpointServer2 
  18.                  type: POST 
  19.                  parameters: m_Html 
  20.                  headers: m_Headers2 
  21.              ]
  22.          } 
  23.          catch(e) 
  24.          { 
  25.              r_GeneratePDF = invokeUrl 
  26.              [ 
  27.                  url: v_EndpointServer3 
  28.                  type: POST 
  29.                  parameters: m_Html 
  30.                  headers: m_Headers3 
  31.              ]
  32.          } 
  33.      } 


This feels like really bad practice

copyraw
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"
  1.  try 
  2.      { 
  3.          v_Test1 = "Foo"
  4.          info v_Test1.toLong()
  5.      } 
  6.      catch(e) 
  7.      { 
  8.          info "Couldn't convert 'Foo' to an integer"
  9.          try 
  10.          { 
  11.              v_Test2 = "Bar"
  12.              info v_Test2.toLong()
  13.          } 
  14.          catch(e) 
  15.          { 
  16.              info "Couldn't convert 'Bar' to an integer"
  17.              try 
  18.              { 
  19.                  v_Test3 = "Everyday I'm Nesting..."
  20.                  info v_Test3.toLong()
  21.   
  22.              } 
  23.              catch(e) 
  24.              { 
  25.                  info "Couldn't convert 'Everyday...' to an integer"
  26.                  try 
  27.                  { 
  28.                      v_Test4 = "Another for the road..."
  29.                      info v_Test4.toLong()
  30.   
  31.                  } 
  32.                  catch(e) 
  33.                  { 
  34.                      info "Couldn't convert 'Another...' to an integer"
  35.   
  36.                  } 
  37.              } 
  38.          } 
  39.      } 
  40.   
  41.  // yields: 
  42.  // "Couldn't convert 'Foo' to an integer" 
  43.  // "Couldn't convert 'Bar' to an integer" 
  44.  // "Couldn't convert 'Everyday...' to an integer" 
  45.  // "Couldn't convert 'Another...' to an integer" 
Category: Zoho :: Article: 894

Add comment

Your rating:

Submit

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

Please publish modules in offcanvas position.