begin
try
assert(false); // not shown when "Stop on Delphi-exceptions" is off,
even when "Asssertions" is on
except
end;
How can I assure that I _always_ get assertions shown, even when "Stop on
Delphi-exceptions" if off and there's a try except around?
Jens
try
assert(false);
except
on E:Exception do showmessage(E.message);
end;
-Howard
procedure bla;
var
ThingsAreOK: boolean;
i : integer;
begin
try
i := DoSomeStuff; // this could cause an ESomeStuffException
ThingsAreOK := Calculate(i);
assert(ThingsAreOK, 'Things are not OK!!!');
except
On E:ESomeStuffException do
ShowMessage('Doing some stuff failed!');
end;
end;
-Howard
in article <97j7bq$ai...@bornews.inprise.com>, you wrote:
it's behaving as designed. The Assertion triggers an exception that you are not
handling. If you don't have "Stop on Delphi Exceptions" checked you won't see
it at all.
--
Regards
Ralph (TeamB)
===
procedure bla;
var
ThingsAreOK: boolean;
i : integer;
begin
try
i := DoSomeStuff; // this could cause an ESomeStuffException
ThingsAreOK := Calculate(i);
assert(ThingsAreOK, 'Things are not OK!!!');
except
On E:ESomeStuffException do
ShowMessage('Doing some stuff failed!');
else raise;
end;
end;
//Jonas
Change the except to
> except
> On E:ESomeStuffException do
> ShowMessage('Doing some stuff failed!')
Else
raise
> end;
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.
According to help, both should behave in exactly the same way. In a small
test I tried this was indeed so.
If you mean that sometimes they behave differently, there's a compiler bug
here.
Thanks for all the answers.
Jens
This code shows the assertion, no matter if "Stop on Delphi-Exceptions" is
on or off:
procedure TForm1.Button1Click(Sender: TObject);
begin
try
assert(false, 'ASSERTION!!!!!');
except
on E:EAssertionFailed do // works with any other Exception-Type as
well
raise;
end;
end;
This code DOESN'Tt show the assertion, when the "Stop on
Delphi-Exceptions"is OFF:
procedure TForm1.Button1Click(Sender: TObject);
begin
try
assert(false, 'ASSERTION!!!!!');
except
MessageBeep(0); // or any other code without ON E:... DO and without
RAISE
end;
end;
Conclusion: if you want to be sure that you see all assertions fired, use
code like the one in the first example. If you work in a team you never
know all hidden assertions in the methods written by others - if you use
these methods in a try-block it seems wise to use "on E:EAssertionFailed..."
for ALL try... except blocks you write!
Jens
> Conclusion: if you want to be sure that you see all assertions fired, use
> code like the one in the first example.
I think you have the wrong conclusion. The more general one, and the correct
one, is: make sure ALL exceptions are handled. Thus, if you have
try
...
except
on SomeException do something;
on SomeOtherException do something else;
else raise; // This line shouldn't be missed
end;
(You may ommit "else raise" if you have trapped Exception).
Do you have a specific reason for this? See my reply to Peter Below.
> > else raise; // This line shouldn't be missed
>
> Do you have a specific reason for this? See my reply to Peter Below.
Goodness, you're right! It's documented and works as you said.
So let's go back to Jens Berke's conclusion:
> This code DOESN'Tt show the assertion, when the "Stop on
> Delphi-Exceptions"is OFF:
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
> try
> assert(false, 'ASSERTION!!!!!');
> except
> MessageBeep(0);
> end;
> end;
>
If you don't have any "on" in the except block, then the except block
itself is considered to be an exception handler. So control does pass to
the except block, so MessageBeep(0) is executed.
After that, the exception is considered handled, so it is not raised any
more, unless you explicitly raise it.
try
assert(false);
except
MessageBeep(0);
raise;
end;
This is probably what you want.