Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Flávio Etrusco
On Sat, Mar 2, 2013 at 7:51 AM, Michael Van Canneyt wrote: > > > On Sat, 2 Mar 2013, Howard Page-Clark wrote: > >> On 02/03/13 5:45, Flávio Etrusco wrote: >>> >>> On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote: (...) > > Also, setting Self to nil is nonsense. > > If you do FreeAndNil(

Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Hans-Peter Diettrich
Sven Barth schrieb: If you want to ensure that MyInstance is Nil you need to do it like this: === code begin === try MyInstance := TMyClass.Create('AnNonExistentFile'); except MyInstance := Nil; end; === code end === When an exception occurs in Create, the assignment will never take pl

Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Howard Page-Clark
On 02/03/13 10:51, Michael Van Canneyt wrote: This will definitely cause a memory leak, because the FPC code does not know that an exception occurred in the constructor (you catch it with Except), and hence will not call the destructor. Thanks for the correction and explanation. Howard -- _

Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Michael Van Canneyt
On Sat, 2 Mar 2013, Howard Page-Clark wrote: On 02/03/13 5:45, Flávio Etrusco wrote: On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote: Hi there, If my class constructor looks like this: constructor TMyClass.Create(fn: string); begin sl := TStringList.Create; try fs := TFil

Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Howard Page-Clark
On 02/03/13 5:45, Flávio Etrusco wrote: On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote: Hi there, If my class constructor looks like this: constructor TMyClass.Create(fn: string); begin sl := TStringList.Create; try fs := TFileStream.Create(fn, fmOpenRead); except se

Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Sven Barth
On 02.03.2013 03:49, Xiangrong Fang wrote: Hi there, If my class constructor looks like this: constructor TMyClass.Create(fn: string); begin sl := TStringList.Create; try fs := TFileStream.Create(fn, fmOpenRead); except self.Destroy; end; end; No, this is a bad idea. If

Re: [Lazarus] exception handling in constructor

2013-03-01 Thread Flávio Etrusco
On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote: > Hi there, > > If my class constructor looks like this: > > constructor TMyClass.Create(fn: string); > begin > sl := TStringList.Create; > try > fs := TFileStream.Create(fn, fmOpenRead); > except > self.Destroy; > end; > end;

[Lazarus] exception handling in constructor

2013-03-01 Thread Xiangrong Fang
Hi there, If my class constructor looks like this: constructor TMyClass.Create(fn: string); begin sl := TStringList.Create; try fs := TFileStream.Create(fn, fmOpenRead); except self.Destroy; end; end; I create the objec like: MyInstance := TMyClass.Create('AnNonExistentFile');

Re: [Lazarus] exception handling

2011-03-13 Thread Marco van de Voort
On Sat, Mar 12, 2011 at 10:53:45PM +0100, Bernd wrote: > 2011/3/9 Hans-Peter Diettrich : > > > An exception down in some calculation doesn't give you any clue of what > > exactly went wrong, only that *something* went wrong. > > It can often be useful and remove a lot of if/else for cleanly exiti

Re: [Lazarus] exception handling

2011-03-13 Thread Hans-Peter Diettrich
Bernd schrieb: 2011/3/9 Hans-Peter Diettrich : An exception down in some calculation doesn't give you any clue of what exactly went wrong, only that *something* went wrong. It can often be useful and remove a lot of if/else for cleanly exiting a bunch of nested loops and functions (and also s

Re: [Lazarus] exception handling

2011-03-12 Thread Bernd
2011/3/9 Hans-Peter Diettrich : > An exception down in some calculation doesn't give you any clue of what > exactly went wrong, only that *something* went wrong. It can often be useful and remove a lot of if/else for cleanly exiting a bunch of nested loops and functions (and also save clock cycle

Re: [Lazarus] exception handling

2011-03-09 Thread Andrea Mauri
Il 09/03/2011 17:29, Mattias Gaertner ha scritto: Some LCL widgetsets use this: {$if defined(cpui386) or defined(cpux86_64)} {$IFDEF windows} Set8087CW($133F); {$ELSE} SetExceptionMask(GetExceptionMask + [exZeroDivide,exInvalidOp]); {$ENDIF} {$ifend} thanks!

Re: [Lazarus] exception handling

2011-03-09 Thread Mattias Gaertner
On Wed, 09 Mar 2011 14:17:19 +0100 Andrea Mauri wrote: > Il 09/03/2011 12:49, Hans-Peter Diettrich ha scritto: > > I'd check this just before the operation, then you won't get an > > exception at all. You can wrap that in a MyLn function, if you need ln() > > more often. > ok. I know. but my ques

Re: [Lazarus] exception handling

2011-03-09 Thread Andrea Mauri
Il 09/03/2011 12:49, Hans-Peter Diettrich ha scritto: I'd check this just before the operation, then you won't get an exception at all. You can wrap that in a MyLn function, if you need ln() more often. ok. I know. but my question is more general and it is: The gui app handles this operation gi

Re: [Lazarus] exception handling

2011-03-09 Thread Hans-Peter Diettrich
Andrea Mauri schrieb: The calculations are under try except. For what reason? An exception down in some calculation doesn't give you any clue of what exactly went wrong, only that *something* went wrong. Sometimes happens that the argument (a) of b:= ln(a) is negative. I'd check this ju

[Lazarus] exception handling

2011-03-09 Thread Andrea Mauri
Dear all, I developed an application that perform some calculations. This application has a gui version and a console version, it runs on windows and linux. Both apps use the same units for calculation, only the interface units are different. I have some problems in the exception handling. Some

[Lazarus] Exception handling in LCLMessageGlue

2010-08-18 Thread Torsten Bonde Christiansen
Hi Lazarus. Please forgive my ignorance if I'm asking a stupid question. In the DeliverMessage function in LCLMessageGlue the Application.HandleException is called with __nil__ as argument. Why is the actual target used here? It is already available at this point, and the callback function a