Expressions - try-catch (or try-except) clause
Hi,
in any expression, is there a way to use the try-catch (try-except) clause? If yes, what is the syntax?
The reason why I need it:
If we have the code with getXPath including filter syntax
-
var collection= Me.getXPath("MyCollection[someVariable = true]");
If there was 1 item found, an object pointing directly to that item will be returned (for example, no "size()" method is then available).
However, if there were 2 or more items found, a list will be returned (".size()" method IS available and we need that one!).
So we need to handle that.
Let me also state that this inconsistent behaviour above is not good... a list should be returned every time, not sometimes object, sometimes list... as there is then twice the work required as two separate blocks of code need to be written, one in case of one found item (returned object) and on in case if two or more found items (returned list) + additional handling... might report it as an idea to get fixed in next versions...
PS: I didn't select a "Category" for this topic as from all of the available options none seems to be relevant directly to expressions (nevertheless if it's for validation, actions, execution script on entry/save/exit...) in Bizagi.
My Bizagi Studio version: 11.2.5.0528 (July 26, 2021).
Kind regards,
Dejan
Hi Dejan,
Please try the following:
var oCollections = CHelper.GetValueAsCollection( Me.getXPath("MyCollection[someVariable = true]") );
CHelper.ThrowValidationAlert(oCollections.size());
You don't need the try/catch block for this, just wrap your code into the CHelper.GetValueAsCollection() method.
Thank you for your answer. I will definitely try this out.
Still, for any other possible situations, is try/catch block possible?
Kind regards,
Dejan
Yes, in some situations I use the try/catch block too.
I've just tried the collections syntax described above and it works perfectly, thanks again.
Regarding the try-catch block, what is the right syntax?
As the syntax below is giving me errors:
try
{
CHelper.trace("", "We're inside try clause");
var a = 1 + "b";
}
catch
{
CHelper.trace("", "We're inside catch clause");
}
Overall, what is the programming language syntax used in Bizagi expressions? Java, C#? Or is it Bizagi's completely own programming language syntax?
Kind regards,
Dejan
Use following try/catch syntax:
try{
//try something
}
catch(error){
CHelper.trace("ErrorFileName", "Error: "+error);
}
Comments have been locked on this page!