浏览代码

* Re-raising exceptions must be allowed only in 'except' block itself, not in 'try' block of a nested try..except statement. Mantis #21873.

git-svn-id: trunk@21100 -
sergei 13 年之前
父节点
当前提交
c08ab0f745
共有 3 个文件被更改,包括 32 次插入2 次删除
  1. 1 0
      .gitattributes
  2. 3 2
      compiler/pstatmnt.pas
  3. 28 0
      tests/webtbf/tw21873.pp

+ 1 - 0
.gitattributes

@@ -11610,6 +11610,7 @@ tests/webtbf/tw21466.pas svneol=native#text/pascal
 tests/webtbf/tw2154.pp svneol=native#text/plain
 tests/webtbf/tw21566.pp svneol=native#text/pascal
 tests/webtbf/tw2174.pp svneol=native#text/plain
+tests/webtbf/tw21873.pp svneol=native#text/plain
 tests/webtbf/tw2209.pp svneol=native#text/plain
 tests/webtbf/tw2242.pp svneol=native#text/plain
 tests/webtbf/tw2273.pp svneol=native#text/plain

+ 3 - 2
compiler/pstatmnt.pas

@@ -831,6 +831,8 @@ implementation
          inc(exceptblockcounter);
          oldcurrent_exceptblock := current_exceptblock;
          current_exceptblock := exceptblockcounter;
+         old_block_type := block_type;
+         block_type := bt_body;
 
          while (token<>_FINALLY) and (token<>_EXCEPT) do
            begin
@@ -860,7 +862,6 @@ implementation
          else
            begin
               consume(_EXCEPT);
-              old_block_type:=block_type;
               block_type:=bt_except;
               inc(exceptblockcounter);
               current_exceptblock := exceptblockcounter;
@@ -988,9 +989,9 @@ implementation
                    p_default:=statements_til_end;
                 end;
 
-              block_type:=old_block_type;
               try_statement:=ctryexceptnode.create(p_try_block,p_specific,p_default);
            end;
+         block_type:=old_block_type;
          current_exceptblock := oldcurrent_exceptblock;
       end;
 

+ 28 - 0
tests/webtbf/tw21873.pp

@@ -0,0 +1,28 @@
+{ %fail }
+{$mode objfpc}{$H+}
+  
+uses
+  Classes, sysutils;     
+var
+    i: integer;
+begin
+      try
+	i:=StrToInt('abc');
+      except
+	    try
+	      writeln('First Exception');
+              // allowed in 'except' block, but not in 'try' part of nested try..except
+	      raise;
+	    except
+	      on econv: EConvertError do
+		  writeln('EConvertError');
+  
+	      on e: Exception do
+		  writeln('Exception');
+  
+	      else
+		  writeln('The Else Block');  
+	    end;
+      end;
+      writeln('After "Try" blocks');
+end.