Hi Abishek, What is meant with 'reduce the use of try/catch' is that you should make sensible use of try/catch and manually throwing exceptions using the error function. Exception handling is (relatively) slow in most languages, so if you have the option to prevent a throw and a catch by simply using an extra if, then do so. On other occasions, you might want to be sure certain statements are always executed, or that certain actions are taken when an exception is thrown.
A good example is trying to connect to an external resource using xdmp:http-get. If it fails with a timeout, it throws an exception. It is not uncommon to put a try catch around it and connect to a different resource, or return some default value instead. Personally, I don't bother about try/catch performance too much. Just use them sensibly.. Kind regards, Geert Van: [email protected] [mailto:[email protected]] Namens Abishek N Verzonden: donderdag 5 mei 2011 19:05 Aan: General MarkLogic Developer Discussion Onderwerp: [MarkLogic Dev General] Try catch in xquery What are the pointers while exception handling in ml? One of the pointers we have already heard is "Reduce the use of try/catch where applicable. This is especially true in situations where try/catch blocks may be nested. Try/catch blocks have a negative impact on performance due to the fact that the block must be completely evaluated before the server can move on. " So does this mean that we have to avoid having try catch blocks around lots of lines of code? and try to keep the try catch block as short as possible.. So in the eg. below statement 3 try catch block would not be triggered until the statement 1 and statement 2 get executed, is that correct? Since statement 2 is outside try catches there is a possibility it could get lazy evaluated. try { statement 1 } catch{ } statement 2 try { statement 3 } catch{ } Similarly in the below scenario.. if we have nested try catches like below... statement 5 would not get executed until statement 1,2,3 get executed.. however statement 4 could get executed.. try { try { statement 1 } catch{ } statement 2 try { statement 3 } catch{ } } statement 4 try { statement 5 } catch{ } Please confirm if our understanding is correct. Regards Abishek
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
