Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-03

EAccessViolation on wrong exception re-raise: intended behavior?

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

leledumbo

Consider the following program:

{$mode objfpc}
uses sysutils;
begin
  try
    try
      raise exception.create('test');
    except
      on e: exception do begin
        e.message := 'tset';
        raise e; // correct re-raise should only have raise; no exception
variable may present
      end;
    end;
  except
    writeln('oow');
  end;
end.

which is a wrong way to re-raise an exception. The program runs but after the outer exception handler ('oow'), it ends with EAccessViolation. Is this the intended behavior?

Reply by email

Michael Van Canneyt
to leledumbo
leledumbo wrote 25 lines
Consider the following program: {$mode objfpc} uses sysutils; begin try try raise exception.create('test'); except on e: exception do begin e.message := 'tset'; raise e; // correct re-raise should only have raise; no exception variable may present end; end; except writeln('oow'); end; end. which is a wrong way to re-raise an exception. The program runs but after the outer exception handler ('oow'), it ends with EAccessViolation. Is this the intended behavior?

I tested in Delphi XE, it also crashes. So, yes it is intended behaviour.

It is not desirable, of course. But there is no way the compiler can decide whether the 'raise e' statement is correct.

Michael.

Reply by email

leledumbo
to Michael Van Canneyt
Show quoted text 5 lines
I tested in Delphi XE, it also crashes. So, yes it is intended behaviour. It is not desirable, of course. But there is no way the compiler can decide whether the 'raise e' statement is correct.

That's bad to know :|
What if you ask Embarcadero first? Probably they missed the point. I don't have Delphi so I can't ask them.

Reply by email

Michael Van Canneyt
to leledumbo
leledumbo wrote 9 lines
> I tested in Delphi XE, it also crashes. So, yes it is intended behaviour. > > It is not desirable, of course. But there is no way the compiler can > decide > whether the 'raise e' statement is correct. That's bad to know :| What if you ask Embarcadero first? Probably they missed the point. I don't have Delphi so I can't ask them.

Like I said, there is no way of knowing what is correct or not.

I don't really see what can be done except maybe checking if an object is already in the exception stack before adding it again (which I assume is what is happening)

Michael.

Reply by email