* * *

Author Topic: TRY-EXCEPT doesnt work in fpc 3.0.0!!! [solved]  (Read 5640 times)

Magicus

  • New member
  • *
  • Posts: 13
TRY-EXCEPT doesnt work in fpc 3.0.0!!! [solved]
« on: January 31, 2017, 01:46:03 pm »
 up vote
0
down vote
favorite
I dont understand, why the code below doesnt get executed?!

Im using: FPC 3.0.0 on Ubuntu 16.04

try
 begin
   //f_start is a record which holds an array within.   
   start_arr := f_start^.Arr;
   (start_arr + index)^ := value;
   //...Fehlerursache
 end;
except On EAccessViolation do
 begin
   //...this code SHOULD BE executed...
 end;�

And the Exception: SIGSEGV: EAccessViolation is raised by....

but the Except block doesnt get executed, why??

Pls can someone help me, im really frustrated now..
« Last Edit: February 02, 2017, 12:00:07 pm by Magicus »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 508
    • My "almost daily" development blog
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #1 on: January 31, 2017, 01:52:28 pm »
If I remember correctly (yeah... I've also had a headache with this :))...
You should "ignore" this exception type. You can do this in project options, or (easier) just click ignore when the exception occurs.
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 3894
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #2 on: January 31, 2017, 01:53:15 pm »
Please show more details. We are only guessing what you mean:
  • "f_start is a record which holds an array within", but: start_arr := f_start^.Arr --> f_start is not a record, it is a pointer to a record!
  • if f_start^.Arr is an array then start_arr muist be an array as well. How can you dereference (start_arr + index)^?
Show all declarations. Otherwise this is just a joke!
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

molly

  • Hero Member
  • *****
  • Posts: 1960
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #3 on: January 31, 2017, 02:00:49 pm »
Besides what was already written, if you put a nil into f_start then you most certainly gain an access violation and the except block is executed.

Magicus

  • New member
  • *
  • Posts: 13
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #4 on: January 31, 2017, 02:15:56 pm »
Ok, sry:

f_start is a pointer to a record, which holds a pointer to an array, as u know, the start-adress of an array:

it looks like:

TBlockPtr = ^Tblock;

TBlock = record
  next: TBlockPtr;
  Arr: ^integer;
end;

the local variable: start_arr is equal to: f_start.Arr !

molly

  • Hero Member
  • *****
  • Posts: 1960
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #5 on: January 31, 2017, 02:30:02 pm »
f_start is a pointer to a record, which holds a pointer to an array, as u know, the start-adress of an array:
Still not seeing any array, sorry. At the most it could be a linked list (that wasn't generated).

Quote
the local variable: start_arr is equal to: f_start.Arr !
So a pointer to an integer... and you index that manually..... that a bit out of the ordinary unless you meant to say that is the array.

Using your structures (and fill in the rest/unknowns myself) it still generates an access violation for me.

Magicus

  • New member
  • *
  • Posts: 13
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #6 on: January 31, 2017, 02:35:56 pm »
What is so hard to understand???

And i guess, you missed the point of this topic, i doesnt even matter that it throws any exception, but i WONDER, why the Try-Except Block isnt executed....

When this would work, i would handle the exception by myself, i dont need your advice for that, just dont know, when EAccessViolation is thrown, it doesnt jump to the "except" block.....

focus on the topic and dont get lost by unnecessary things..
« Last Edit: January 31, 2017, 02:38:37 pm by Magicus »

molly

  • Hero Member
  • *****
  • Posts: 1960
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #7 on: January 31, 2017, 02:44:06 pm »
What is so hard to understand???
Trying to understand what part of your memory you are overwriting.

Quote
And i guess, you missed the point of this topic,
No i did not. You are by not providing the minimal information required to answer your question.

Quote
i doesnt even matter that it throws any exception, but i WONDER, why the Try-Except Block isnt executed....
Becuase you are doing something stupid like overwriting memory. But, we will never know because you leave us in the dark.

Quote
When this would work, i would handle the exception by myself, i dont need your advice for that, just dont know, when EAccessViolation is thrown, it doesnt jump to the "except" block.....

Quote
focus on the topic and dont get lost by unnecessary things..
Ok so asking for how your data is structured and what you do with it is unnecessary... thanks for completely wasting my time.

To answer your original question: "it is magic."

wp

  • Hero Member
  • *****
  • Posts: 3894
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #8 on: January 31, 2017, 02:52:27 pm »
focus on the topic and dont get lost by unnecessary things..
Hey come on! If you don't provide all information needed nobody can decide what is unnecessary. With that attitude nobody will be willing to help you.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

GetMem

  • Hero Member
  • *****
  • Posts: 2417
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #9 on: January 31, 2017, 02:54:52 pm »
Quote
but i WONDER, why the Try-Except Block isnt executed....
Replace EAccessViolation with Exception like this:
Code: Pascal  [Select]
  1.  try
  2.   //f_start is a record which holds an array within.  
  3.   start_arr := f_start^.Arr;
  4.   (start_arr + index)^ := value;
  5.   //...Fehlerursache
  6.  except
  7.    on e: Exception do
  8.    begin
  9.      ShowMessage('Crap');
  10.      //...
  11.    end;
  12. end;
  13.  
If still not works run the executable outside the IDE.

PS: Please be polite with others, they are trying to help you after all.

bylaardt

  • Full Member
  • ***
  • Posts: 246
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #10 on: January 31, 2017, 02:55:15 pm »
What is so hard to understand???

And i guess, you missed the point of this topic, i doesnt even matter that it throws any exception, but i WONDER, why the Try-Except Block isnt executed....

When this would work, i would handle the exception by myself, i dont need your advice for that, just dont know, when EAccessViolation is thrown, it doesnt jump to the "except" block.....

focus on the topic and dont get lost by unnecessary things..
Probably is not a EAccessViolation
Code: Pascal  [Select]
  1.  try  
  2.   //your hided code
  3.   except
  4.     on e:Exception do
  5.      shomessage('Error type is '+e.classname);
  6.   end;
  7.  
  8.  

Magicus

  • New member
  • *
  • Posts: 13
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #11 on: January 31, 2017, 02:57:23 pm »
How can't overwriting memory not lead to try-except block, when this is true, what you say, this is the most crappiest and fatal design by fpc-developer...

In every other language you are able to catch those errors!

Ok: when you want to know my structure so badly, here is it...

I am creating a TBlock: (defined in some earlier posts)

in my class, i create such a memory-block which has:

* a "next" pointer to the same type
* a pointer to the start-adress of an array

so the TBLOCK is just an pointerholderrecord, if you want and my idea is, in the constructor i create such a block of memory with an initial-capacity, for example: 1000 array- values and 1-next pointer which is nil at the first-time

and in my: Write(index, value) function,

i want to write an element at a given position, ok:

But when i run the write(...) in a for loop of 40000 items, at one index, (mostly by round about index 33000)
SIGSEGV is raising and from there it doesnt execute..


« Last Edit: January 31, 2017, 02:59:34 pm by Magicus »

molly

  • Hero Member
  • *****
  • Posts: 1960
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #12 on: January 31, 2017, 02:59:50 pm »
And to counterpart the statement "TRY-EXCEPT doesnt work in fpc 3.0.0!!!"

Code: Pascal  [Select]
  1. program ForceException;
  2.  
  3. {$MODE OBJFPC}{$H+}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. Type
  9.   PSomeData = ^TSomeData;
  10.   TSomeData = Integer;
  11. var
  12.   SomePointer: PSomeData;
  13. begin
  14.   SomePointer := nil;
  15.  
  16.   try
  17.     SomePointer^ := $12345678;
  18.    except
  19.     On E: EAccessViolation do
  20.     begin
  21.       WriteLn('Oops acces violation');
  22.     end;
  23.   end;
  24. end.
  25.  

So, exception based on acces violation _DO_ work in fpc 3.0 (and all other version of FPC for that matter). Just not for your case because you are doing something else (and that information about that something else i was trying to gather, in order to be able to anwer the question why the except block does not execute for you).

Magicus

  • New member
  • *
  • Posts: 13
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #13 on: January 31, 2017, 03:04:19 pm »
Im sry for the rude tone, but im really pissed of by this problem currently...

Ok, i switched from EAccessViolation to general Exception, but it still doesnt work... :(

rvk

  • Hero Member
  • *****
  • Posts: 2945
Re: TRY-EXCEPT doesnt work in fpc 3.0.0!!!
« Reply #14 on: January 31, 2017, 03:04:31 pm »
How can't overwriting memory not lead to try-except block, when this is true, what you say, this is the most crappiest and fatal design by fpc-developer...
Have you tried Run > Run without Debugging like suggested multiple times already here?

You'll see it works fine.
So it's not a problem of FPC.
It's only that Lazarus (or the debugger GDB) trips over the exception (like already mentioned).

AFAIK you can't Try/Except an "External: SIGSEGV".
« Last Edit: January 31, 2017, 03:09:47 pm by rvk »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus