![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 4 of 4 total |
![]() |
Mon, May 9 2016 10:14 AM | Permanent Link |
Matthew Jones | How expensive are exceptions in EWB JavaScript?
I have a validation routine that validates user input to check it is a valid percentage, float, or currency value. As part of the validation, it needs to strip things like percent signs, and so it makes sense for it to calculate the value too. However, with no var parameters, I can only return true or false for valid or not. Thus I'm currently using a "GetLastValue" function that returns a value stored in a global by the validator. procedure TfrmDetailEdit.editQtyChange(Sender: TObject); var szText : String; bValid : Boolean; begin if m_bLoading then exit; szText := editQty.Text; bValid := IsValidDEC(szText); if bValid then begin m_xItemMaterial.QuantityDEC := LastValidDEC; UpdateFromLine; end; editQty.Error := not bValid; end; But it struck me that it might be better to encapsulate it all with a function that assumes all is well, but throws an exception if it was bad: procedure TfrmDetailEdit.editQtyChange(Sender: TObject); begin if m_bLoading then exit; try m_xItemMaterial.QuantityDEC := IsValidDEC(editQty); UpdateFromLine; except end; end; I'd pass in the edit field, so it could set the valid/invalid state, get the text, and return the validated value. If there was a problem, it would raise the exception, and the code would be inert. But how expensive are exceptions? -- Matthew Jones |
Mon, May 9 2016 11:24 AM | Permanent Link |
Raul Globestar Systems ![]() | On 5/9/2016 10:14 AM, Matthew Jones wrote:
> How expensive are exceptions in EWB JavaScript? I'm no expert but looks like you're doing UI code so i would say don't worry about it since exception cost would not be even in the same cost factor universe as UI and user input timings. Raul |
Mon, May 9 2016 11:50 AM | Permanent Link |
Matthew Jones | Raul wrote:
> looks like you're doing UI code so i would say don't worry about it > since exception cost would not be even in the same cost factor > universe as UI and user input timings. Indeed, I was thinking that, but it is possible that these things will ripple through, so I'd like to know if avoiding a cascade is important or not. It is possible that I have to do a few thousand calculations for an update at some point (not sure at this point, probably a few hundred max). -- Matthew Jones |
Mon, May 9 2016 2:51 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Matthew,
<< How expensive are exceptions in EWB JavaScript? >> Chrome's V8 JS engine won't optimize any try..except/finally blocks, so there's that, but I wouldn't worry about it because you won't ever notice the difference. As for actually *throwing* the exceptions, that could become expensive and should be avoided if you think it's going to be a common occurrence. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Thursday, March 30, 2023 at 10:19 AM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |