Forum > Beginners

Try Finally Except - Help

(1/2) > >>

Tony Stone:
I am trying to clean up a lot of my code messes.  I am trying to implement error handling where possible and this is my first go at use try...except... statements.  I have used them, typically what I copied from examples on the net.  I really need my procedure to exit or abort if an exception happens.  Simply calling exit; after the On E: EInOutError do gives me a compile error.  Expects end;

This is a sample of my attempt, can I only have one statement for the on E: do ... statement?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  if dlgFMsaveTarget.Execute then  begin    // create target file    try      AssignFile(TargetFileOD, dlgFMsaveTarget.FileName);      Rewrite(TargetFileOD);      CloseFile(TargetFileOD);    except      on E: EInOutError do        ShowMessage('File handling error occurred. Details: ' +          E.ClassName + '/' + E.Message);       //exit; // there was an error... need to get out of entire procedure    end;  end else exit; //user pressed cancel in dialog - get out of here startProcessing;  

Fantablup:
          except
            on E: EDatabaseError do
            begin
              ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message );
              ShowMessage( 'hey dude ');
            end;
            on E: Exception do
            begin
              ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );
            end;
          end;

sstvmaster:

--- Quote from: Tony Stone on July 13, 2021, 12:47:03 am ---.
..Simply calling exit; after the On E: EInOutError do gives me a compile error.  Expects end;

...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...    except      on E: EInOutError do        begin // <--          ShowMessage('File handling error occurred. Details: ' + E.ClassName + '/' + E.Message);          exit;        end; // <--    end;...
--- End quote ---

Tony Stone:
DOH!!!!   :-[


I feel I need to delete this post now!  I am embarrassed.  Thank you!  Or i'll just leave it for other newbies...

Grrr!  This was a simple lesson with if then statements.  I really canot beleive I posted this question in public... lol

--- Quote from: sstvmaster on July 13, 2021, 12:56:07 am ---
--- Quote from: Tony Stone on July 13, 2021, 12:47:03 am ---.
..Simply calling exit; after the On E: EInOutError do gives me a compile error.  Expects end;

...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...    except      on E: EInOutError do        begin // <--          ShowMessage('File handling error occurred. Details: ' + E.ClassName + '/' + E.Message);          exit;        end; // <--    end;...
--- End quote ---

--- End quote ---

Fantablup:
Nothing to be embarrassed about.
We all have been there :)

Navigation

[0] Message Index

[#] Next page

Go to full version