View Issue Details

IDProjectCategoryView StatusLast Update
0035588LazarusLCLpublic2019-05-25 07:21
ReportersembitAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.1 (SVN)Product Build61228 
Target VersionFixed in Version 
Summary0035588: Division by zero when trying to access a non-existing tab.
DescriptionPageControl1.Pages[-1].Caption raises this exception. The idea should be another exception. For example, the index out of range. Because of this, my application crashes.
TagsNo tags attached.
Fixed in Revisionr61289
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

sembit

2019-05-15 19:04

reporter  

TestPageControl.zip (129,001 bytes)

Bart Broersma

2019-05-15 22:38

developer   ~0116215

I get:
ERROR in code: TNBPages.GetObject Index out of bounds
Creating gdb catchable error

sembit

2019-05-16 13:50

reporter   ~0116217

I have so.

error.jpg (126,031 bytes)
error.jpg (126,031 bytes)

Juha Manninen

2019-05-22 16:33

developer   ~0116337

Accessing a non-existing tab is clearly an error. You can catch an exception in your code if needed. I don't see what is the bug here.
Planning to resolve as "no change required".

sembit

2019-05-23 07:45

reporter   ~0116361

Last edited: 2019-05-23 07:49

View 2 revisions

I can't catch the exception in try block.
For example, a TStringList raises an EStringListError exception when you access a nonexistent index. Why not do it for TPageControl as well, so that the program "lands more softly" when it falls? Most classes are implemented as TSringList. It turns out that every time you need to check the index in the "if" block or write your descendant.

Juha Manninen

2019-05-23 10:11

developer   ~0116364

Ok. Do you have an implementation in mind? If you do, please provide a patch.

sembit

2019-05-23 12:37

reporter   ~0116368

You just need to remove the check in the code:

function TNBPages.GetObject (Index: Integer): TObject;
begin
   {if (Index <0) or (Index> = FPageList.Count) then
     RaiseGDBException ('TNBPages.GetObject Index out of bounds'); }
   Result: = TObject (FPageList [Index]);
end;

Do the same in other methods. Then the exception of EListError will be raised and it can be caught.

Michal Gawrycki

2019-05-23 16:38

reporter   ~0116372

From "RaiseGDBException" description:
>Normally gdb does not catch fpc Exception objects, therefore this procedure
>raises a standard "division by zero" exception which is catched by gdb.
>This allows one to stop a program, without extra gdb configuration.

Is it still valid? It seems that currently GDB is catching FPC exceptions. If so, we can change RaiseGDBException call with the standard "raise exception.create..."

Juha Manninen

2019-05-24 23:17

developer   ~0116399

Yes, GDB now catches FPC exceptions. I removed the extra "division by zero" exceptions.
The only issue comes when FPC libs are built without debug info while debugging LCL. Then you don't get a proper stack trace. However that same thing happens with all LCL code obviously.

If you want to remove other similar "division by zero" exceptions from LCL code, please open a new issue with a patch.

sembit

2019-05-25 07:21

reporter   ~0116404

Thanks!

Issue History

Date Modified Username Field Change
2019-05-15 19:04 sembit New Issue
2019-05-15 19:04 sembit File Added: TestPageControl.zip
2019-05-15 22:38 Bart Broersma Note Added: 0116215
2019-05-16 13:50 sembit File Added: error.jpg
2019-05-16 13:50 sembit Note Added: 0116217
2019-05-22 16:33 Juha Manninen Assigned To => Juha Manninen
2019-05-22 16:33 Juha Manninen Status new => feedback
2019-05-22 16:33 Juha Manninen LazTarget => -
2019-05-22 16:33 Juha Manninen Note Added: 0116337
2019-05-23 07:45 sembit Note Added: 0116361
2019-05-23 07:45 sembit Status feedback => assigned
2019-05-23 07:49 sembit Note Edited: 0116361 View Revisions
2019-05-23 10:11 Juha Manninen Note Added: 0116364
2019-05-23 12:37 sembit Note Added: 0116368
2019-05-23 16:38 Michal Gawrycki Note Added: 0116372
2019-05-24 23:17 Juha Manninen Status assigned => resolved
2019-05-24 23:17 Juha Manninen Resolution open => fixed
2019-05-24 23:17 Juha Manninen Fixed in Revision => r61289
2019-05-24 23:17 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2019-05-24 23:17 Juha Manninen Note Added: 0116399
2019-05-25 07:21 sembit Status resolved => closed
2019-05-25 07:21 sembit Note Added: 0116404