Struggling with Try lazarus / 21-General ---------------------------------------------------------------------- Spoonhorse · 2021-11-21 08:01 So, there's a way my users can publish their own version of my app, and they can include fonts with it. I thought it would be helpful to automatically include the fonts they're definitely using. It is hard to find the association between a font's filename in the Fonts folder and the name of the font. Fortunately a forum member called Mr.Madguy has written a thing which peeks directly at the file and extracts a name from it. https://forum.lazarus.freepascal.org/index.php?topic=37329.0 It works! Except when it doesn't. Sometimes it crashes and burns with an 'External: ACCESS VIOLATION, for example on the arialbd.ttf file, and this is weird, because his code is wrapped up in try statements. I didn't really know how to debug his code, so I just wrapped the bit where I call his code in more try statements. This didn't work. It still gives me the access violation. 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   for i := 1 to ComboBox1.Items.Count do     begin     try        try        FontInfo := FindTrueTypeFontName('C:\Windows\Fonts\'+ComboBox1.Items[i - 1]);        except        on E: Exception do           ShowMessage( 'Hi! We are handling the error: '+ E.ClassName + #13#10 + E.Message );        end;     finally        if (FontInfo <> '') and               ((FontInfo = Translate('Default title font'))                 or (FontInfo = Translate('Default body font'))                 or (FontInfo = TitleFont)                 or (FontInfo = MainFont)) then           ListBox1.Items.Add(ComboBox1.Items[i - 1]);        end;     end; I've never really messed with try blocks in Pascal because I've been trying to prevent the conditions that might cause errors, rather than handling them when they arise. But isn't this exactly the sort of thing they're meant to prevent? What's going on? Thanks. ---------------------------------------------------------------------- dbannon · 2021-11-21 09:39 Spoonhorse, did you test this outside of the IDE ?  Using the IDE and the debugger, exceptions are shown even if you have handled them. Davo ---------------------------------------------------------------------- ASerge · 2021-11-21 09:45 And since you don't free up resources here, you don't need the finally block. In addition, all protected code must be written inside try: 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   for i := 1 to ComboBox1.Items.Count do  try    FontInfo := FindTrueTypeFontName('C:\Windows\Fonts\' + ComboBox1.Items[i - 1]);  if (FontInfo <> '') and      ((FontInfo = Translate('Default title font')) or      (FontInfo = Translate('Default body font')) or      (FontInfo = TitleFont) or (FontInfo = MainFont)) then      ListBox1.Items.Add(ComboBox1.Items[i - 1]);  except    on E: Exception do      ShowMessage('Hi! We are handling the error: ' + E.ClassName +        #13#10 + E.Message);  end; ---------------------------------------------------------------------- Spoonhorse · 2021-11-21 10:58 Thank you both. The new version does indeed work fine outside of the IDE. It would be nice to be able to disable the debugger in the IDE to test stuff like this, but I'm having trouble doing it. There's a thread about it here ... https://forum.lazarus.freepascal.org/index.php?topic=42789.0 ... but I don't see what that person is seeing when I go to the IDE options and General, I don't see the crucial dropdown menu they're talking about, I see the thing in the attachment. ---------------------------------------------------------------------- Spoonhorse · 2021-11-21 11:01 Oh P.S. if anyone can figure out why Mr.Madguy's code chokes on some files and make it stop doing that, I would be most grateful. But the feature is only a minor convenience to a small subset of my users and the problem only affects a small number of fonts so it's not a big deal. ---------------------------------------------------------------------- trev · 2021-11-21 11:27 Quote from: Spoonhorse on November 21, 2021, 11:58:55 amIt would be nice to be able to disable the debugger in the IDE to test stuff like this, but I'm having trouble doing it. There's a thread about it here ... What's wrong with the Main  menu > Run > "Run without debugging" option? Quotewhen I go to the IDE options and General, I don't see the crucial dropdown menu they're talking about, The interface in Lazarus 2.2 has changed since that post. Look under "Debugger backend" now.