私はバイト配列に2つのバイトを組み合わせて、次のコードがあります。エイダ: - 「No_Exception_Propagation」の違反パート2
pragma Restrictions (No_Exception_Propagation);
with Interfaces; use Interfaces;
procedure No_Propagation is
type Byte is new Unsigned_8;
type Byte_Array is array (Natural range <>) of Byte;
function Concat (Input_1 : Byte;
Input_2 : Byte)
return Byte_Array
is
Null_Array : Byte_Array (1 .. 0);
begin
declare
Output : constant Byte_Array := Byte_Array'(Input_1 & Input_2);
begin
return Output;
exception
when Constraint_Error =>
return Null_Array;
end;
end Concat;
A, B : Byte;
begin
A := 5;
B := 0;
declare
C : Byte_Array := Concat(A, B);
begin
null;
end;
end No_Propagation;
を私はこれをコンパイルすると:
gnatmake -gnatw.e no_propagation.adb
私が手次の警告:
no_propagation.adb:16:66: warning: pragma Restrictions (No_Exception_Propagation) in effect
no_propagation.adb:16:66: warning: "Constraint_Error" may result in unhandled exception
Q1。 Concat関数内の宣言ブロックに例外ハンドラがあると、 "Constraint_Error"が未処理の例外を引き起こす可能性があるという警告が表示されるのはなぜですか?
Q2。 2バイトをまとめてByte_Arrayに貼り付けると、どのようにしてConstraint Errorが生成されますか?
例外ハンドラは 'begin'の後のすべてを保護しますが、初期化はその前です...' End'プロシージャの前にハンドラが必要だと思います。 –