try except fails inside while loop [solved] lazarus / 62-General ---------------------------------------------------------------------- bigDan · 2021-05-25 20:21 I'm using Win-64 2.0.12 of Lazarus. This is the first time I've used this version of the compiler and I believe the first time I've used the 64bit windows compiler. I am having a very odd issue. I'm not sure if I'm doing something completely lame that I just don't see or if there is a compiler problem. The gist of the problem is I want to process an exception inside a while loop and keep on processing more data: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i while do begin  try    someprocedure; // this can generate an exception  except      end;end;  The problem is, when the exception occurs, I never get to , the program just stops. If I move the try/except to enclose the entire loop, that exception is processed correctly but now the while loop has been terminated by the exception. Enclosed is a simple test program that produces what I am seeing. Use {$undefine works} and it will compile the code with the try/except  inside the loop - the code I want to have work. In the {$undefined works} code, I would expect to see both 'failed', and 'after try' but neither are displayed. Use {$define works} and it will compile code with the while loop enclosed by try/except. This works, but isn't what I need. I have used exceptions often in the past, including my own. The only thing I can think I'm doing different than in the past is I'm testing the exception in the outblock, not a called procedure. --------------------------------- Some additional information (added after initial post): compiled the test program on another PC which is using 32bit Lazarus 2.0.10/FPC 3.2.0 and I am seeing the results I would expect: after try failed after try failed ... The compiler with the problem is 64bit Lazarus 2.0.12 / FPC 3.2.0. Same FPC compiler, different results. Is this a 64bit issue? ---------------------------------------------------------------------- bigDan · 2021-05-25 20:57 I have installed 32bit Lazarus 2.0.12 / FPC 3.2.0 on the original system exhibiting the problem. The test program works fine now, as does the program in question. I cannot find any bugs with try / while. Not sure if this is a known problem or new. ---------------------------------------------------------------------- Martin_fr · 2021-05-25 21:29 Afaik 32 bit (win) still uses the "old" exception system. 64bit uses SEH exceptions. So there is a difference. I also get the error with the 3.2.2RC (I have not yet installed the final release. I would say it is a bug in the compiler. The asm output shows Code: [Select].seh_handler __FPC_specific_handler,@except,@unwind .seh_handlerdata .section .text.n_main,"x" .seh_endproc And I am not sure, but I thought there ought to be data after seh_handlerdata (There is in the working version). Seems to work in fpc trunk ---------------------------------------------------------------------- marcov · 2021-05-25 21:46 Quote from: Martin_fr on May 25, 2021, 11:29:10 pmAfaik 32 bit (win) still uses the "old" exception system. 64bit uses SEH exceptions. FPC < 3.2.0 is as you described. FPC 3.2.0+ both have SEH. ---------------------------------------------------------------------- Bart · 2021-05-26 20:29 It fails with win64 if any optimization is used. It works with -O-. Same happens in fpc 3.0.4 and fpc 3.2.0 b.t.w. So at least it's not a regression. If you change "while true" to something that is actually calculated at runtime, it works with any optimazation level. In trunk it works OK. Bart ---------------------------------------------------------------------- bigDan · 2021-05-27 01:00 Thanks. My project will be ported to a raspberry pi next week so it will become a moot point for me and looks like it is fixed for the next release. ---------------------------------------------------------------------- Bart · 2021-05-27 10:41 It is however unclear if it will be fixed in the next point-release: 3.2.4. Bart ---------------------------------------------------------------------- Bart · 2021-05-29 10:45 Does anybody know in what revision this was fixed and wether or not there was a bugreport about it? Bart ---------------------------------------------------------------------- ad1mt · 2023-12-11 16:41 QuoteI'm working on a big integer library, and have been using the 64bit compiler. Just out of curiosity, I ran my tests using a version compiled by the 32bit compiler, and ran into problems with PFE exception handling.  The 64bit code worked fine, but the 32bit code did not, and behaved in a way that looked buggy to me.I take back what I said... the problem was that the compiler was using a 32bit integer for intermediate calculations in an expression. When I forced all variables/constants to 64bit in the expression, the problem was fixed.