⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtry.out

📁 格式化源码的最新板
💻 OUT
字号:
unit testtry;

interface

implementation

uses Dialogs, SysUtils, Math;

procedure testraise;
begin
  raise Exception.Create('Monkey error: please insert soy');
end;

procedure testraiseat;
begin
  raise Exception.Create('Shatner error: please insert toupee')at @testraiseat;
end;

procedure testtryraise;
begin
  try
    ShowMessage('Start');
  except
    ShowMessage('except');
    raise
  end;
end;

procedure testtryproc;
begin
  try
    ShowMessage('Start');
    try
      ShowMessage('trying');
      try
        ShowMessage('still trying');
      finally
        ShowMessage('going...');
      end;
    except
      ShowMessage('except');
    end;
  finally
    ShowMessage('Finally!');
  end;
end;

procedure simple;
begin
  try
    testtryproc;
  except
  end;
  try
    testtryproc;
  except
    ShowMessage('It Failed');
  end;
end;

procedure exceptblock;
begin
  try
    testtryproc;
  except
    on e: Exception do
    begin
      ShowMessage('There was an exception: ' + e.message);
    end;
  end;
end;

procedure complex;
var
  liloop: integer;
begin
  try
    liloop := 0;
    while liloop < 10 do
    begin
      testtryproc;
      Inc(liloop);
    end;
  except
    on e: Exception do
    begin
      ShowMessage('There was an exception: ' + e.message);
    end;
  end;
end;

procedure testsimpleelse;
begin
  try
    testtryproc;
  except
    on e2: einvalidargument do
      ShowMessage('There was an invalid arg exception: ' + e2.message);
    else
      raise;
  end;
  try
    testtryproc;
  except
    on e: ematherror do
    begin
      ShowMessage('There was a math error: ' + e.message);
    end
    else
    begin
      raise;
    end;
  end;
  try
    testtryproc;
  except
    on e: ematherror do
    begin
      ShowMessage('There was a math error: ' + e.message);
    end
    else;
  end;
  try
    testtryproc;
  except
    on e: ematherror do
    begin
      ShowMessage('There was a math error: ' + e.message);
    end
    else
    begin
    end;
  end;
end;

procedure morecomplexexceptionhandler;
var
  liloop: integer;
begin
  try
    testtryproc;
  except
    on e2: einvalidargument do
      ShowMessage('There was an invalid arg exception: ' + e2.message);
    on e: ematherror do
    begin
      ShowMessage('There was an exception: ' + e.message);
    end;
    on eoverflow do
      ShowMessage('There was an underflow exception');
    else
      raise;
  end;
end;

procedure testreraise;
begin
  try
    testtryproc;
  except
    ShowMessage('There was an exception');
    raise;
  end;
end;

procedure testreraise2;
var
  li: integer;
begin
  try
    testtryproc;
  except
    ShowMessage('There was an exception');
    ShowMessage('There was an exception');
    li := 0;
    ShowMessage('There was an exception');
    for li := 0 to 10 do
      ShowMessage('There was an exception');
    begin
      testtryproc;
    end;
    raise;
  end;
end;

procedure testbigfinally;
var
  li: integer;
begin
  try
    testtryproc;
  finally
    ShowMessage('There was an exception');
    ShowMessage('There was an exception');
    li := 0;
    ShowMessage('There was an exception');
    for li := 0 to 10 do
      ShowMessage('There was an exception');
    begin
      testtryproc;
    end;
  end;
end;

end.
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -