[fpc-pascal] FPCUnit test + raise E;
Sven Barth
pascaldragon at googlemail.com
Sun Sep 15 11:56:27 CEST 2013
On 15.09.2013 03:21, Marcos Douglas wrote:
> Hi,
>
> 1) I have a code like that:
>
> procedure TghSQLConnector.Connect;
> begin
> try
> FLib.Connect;
> except
> on E: Exception do
> DoOnException(E);
> end;
> end;
>
> https://github.com/mdbs99/Greyhound/blob/0.1.8/src/ghsql.pas#L1565
>
>
> 2) DoOnException was implemented so:
>
> procedure TghSQLHandler.DoOnException(E: Exception);
> begin
> if Assigned(FOnException) then
> FOnException(Self, E)
> else
> raise E;
> end;
>
> https://github.com/mdbs99/Greyhound/blob/0.1.8/src/ghsql.pas#L443
>
>
> So, as you see, if occurs a Exception the code checks if the event
> (OnException) was setted. If yes, call user implementation; if no,
> call raise E;
> It works... but not when I uses in FPCUnit tests.
>
> See a simple test (this works):
>
> procedure TghSQLConnectorTest.TestOnException;
> begin
> // catch
> FConn.OnException := @DoOnException;
> FConn.Script.Text := 'foo';
> FConn.Execute;
> end;
>
> https://github.com/mdbs99/Greyhound/blob/0.1.8/test/ghsqltest.pas#L246
>
>
> The code DoOnException is:
>
> procedure TghSQLTest.DoOnException(Sender: TObject; E: Exception);
> begin
> AssertTrue(Assigned(E));
> end;
>
> https://github.com/mdbs99/Greyhound/blob/0.1.8/test/ghsqltest.pas#L141
>
> So, if I change the test like bellow... BUM! SIGSEGV!!
>
> procedure TghSQLConnectorTest.TestOnException;
> begin
> // removed >>> FConn.OnException := @DoOnException;
> FConn.Script.Text := 'foo';
> FConn.Execute;
> end;
>
>
> The ERROR is:
> [Content]
> Project test raised exception class 'External: SIGSEGV'.
>
> At address 40B758
Could you as a test replace the
raise E
with
raise E at get_caller_addr(get_frame), get_caller_frame(get_frame);
and check whether this makes a difference?
Could you also compile the RTL with debug information and maybe also
without optimizations (CROSSOPT="-gl -O-") and rerun your test and
display the stack trace (you'll need to enable "-gl" for your test as well)?
Regards,
Sven
More information about the fpc-pascal
mailing list