Sign in Join

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

Mailing lists / lazarus / 2009-12

Exception hidden ?

13 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

JoshyFun

Hello Lazarus-List,

Can anybody tell me why this code does not raise an exception and silently kills the program ?

---------------------------------------------------
unit ufrmmain;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs
  ,httpserv;
type
  TForm1 = class(TForm)
  private
    { private declarations }
  public
    { public declarations }
  end;
var
  Form1: TForm1;
  S: TFileStream;
implementation
initialization
  {$I ufrmmain.lrs}
  S:=TFileStream.Create('NonExistsFilename',fmOpenread);
end.
---------------------------------------------------

But this initialization works as expected:

---------------------------------------------------
initialization
  {$I ufrmmain.lrs}
  try
    S:=TFileStream.Create('NonExistsFilename',fmOpenread);
  except
    Raise Exception.Create('Message');
  end;
end.
---------------------------------------------------

I'm using fpc 2.5.1 SVN and Lazarus SVN 5 days ago. Thank you.

Best regards, JoshyFun

Reply by email

Bart
to JoshyFun
JoshyFun wrote
Can anybody tell me why this code does not raise an exception and silently kills the program ?

It actually does raise an exception.

bart at simenon:~/LazarusProjecten> ./leeg
[FORMS.PP] ExceptionOccurred
Sender=EFOpenError
Exception=Unable to open file "NonExistsFilename"
Stack trace:
$0808EAA8
$080877F1 UFRMMAIN_init, line 27 of ufrmmain.pas $0806D2B4
TApplication.HandleException Unable to open file "NonExistsFilename" Stack trace:
$0808EAA8
$080877F1 UFRMMAIN_init, line 27 of ufrmmain.pas $0806D2B4
exception at 0808EAA8:
Unable to open file "NonExistsFilename".

Just run the program from commandline (in Windows uncheck Win32 GUI application in Project -> Compiler Options -> Linking, or put {$APPTYPE CONSOLE} at top of your .lpr file)

The unhandled exception is handled by the deafult exception handler, which (I guess) at that point in time, is not the exception handler that you expect (the fancy one showing the message with option Continue/Terminate).

I think it all has to do with at what time which exceptionhandler is initialised.

Bart

Reply by email

JoshyFun
to Bart

Hello Lazarus-List,

Friday, December 25, 2009, 12:07:46 AM, you wrote:

B> Just run the program from commandline (in Windows uncheck Win32 GUI B> application in Project -> Compiler Options -> Linking, or put B> {$APPTYPE CONSOLE} at top of your .lpr file)

But my program is not a console application. It does not show any kind of error (stdout does not exists, I'm on windows).

B> The unhandled exception is handled by the deafult exception handler, B> which (I guess) at that point in time, is not the exception handler B> that you expect (the fancy one showing the message with option B> Continue/Terminate).
B> I think it all has to do with at what time which exceptionhandler is B> initialised.

It takes me one hour to find the initialization section that raises the exception (third party units). Also in GDB it shows something like:

Program terminated with error code 1303

i'm not sure about the number, as I'm not in a computer with Lazarus.

I expect some kind of "visible" error, with a possible backtrace to catch where the application crashes.

Best regards, JoshyFun

Reply by email

Paul Ishenin
to JoshyFun
JoshyFun wrote 10 lines
It takes me one hour to find the initialization section that raises the exception (third party units). Also in GDB it shows something like: Program terminated with error code 1303 i'm not sure about the number, as I'm not in a computer with Lazarus. I expect some kind of "visible" error, with a possible backtrace to catch where the application crashes.

Can you create a small test and attach it to the fpc bug tracker?

Best regards,
Paul Ishenin.

Reply by email

Hans-Peter Diettrich
to JoshyFun: B> Just run the program from commandline (in Windows uncheck Win32 GUI B> application in…
Show quoted text 6 lines
B> Just run the program from commandline (in Windows uncheck Win32 GUI B> application in Project -> Compiler Options -> Linking, or put B> {$APPTYPE CONSOLE} at top of your .lpr file) But my program is not a console application. It does not show any kind of error (stdout does not exists, I'm on windows).

On Windows you can uncheck the option (see above), to get a GUI application with an attached console. A very nice feature for debugging, not available on most other platforms.

DoDi

Reply by email

JoshyFun
to Hans-Peter Diettrich: On Windows you can uncheck the option (see above), to get a GUI application with an…

Hello Lazarus-List,

you wrote 5 lines
> B> Just run the program from commandline (in Windows uncheck Win32 GUI > B> application in Project -> Compiler Options -> Linking, or put > B> {$APPTYPE CONSOLE} at top of your .lpr file) > But my program is not a console application. It does not show any kind > of error (stdout does not exists, I'm on windows).

HPD> On Windows you can uncheck the option (see above), to get a GUI HPD> application with an attached console. A very nice feature for debugging, HPD> not available on most other platforms.

I know, in fact I'm using it a lot in combination with writeln. In fact my problem is solved, but a beginner that uses a unit that raises an exception will think that either the package is completly wrong or that Lazarus is wrong as no error is shown.

Best regards, JoshyFun

Reply by email

Brad Campbell
to Hans-Peter Diettrich: On Windows you can uncheck the option (see above), to get a GUI application with an…
Hans-Peter Diettrich wrote
On Windows you can uncheck the option (see above), to get a GUI application with an attached console. A very nice feature for debugging, not available on most other platforms.

Actually not _required_ on other platforms. Other platforms let you run an application from a console and witness its output should you so desire, without having to recompile the application with odd options.

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Hans-Peter Diettrich
to Brad Campbell
Show quoted text 7 lines
> On Windows you can uncheck the option (see above), to get a GUI > application with an attached console. A very nice feature for > debugging, not available on most other platforms. Actually not _required_ on other platforms. Other platforms let you run an application from a console and witness its output should you so desire, without having to recompile the application with odd options.

Thanks, I didn't know that it's so easy.

The same procedure should be possible on Windows?

DoDi

Reply by email

Zaher Dirkey
to Brad Campbell: Actually not _required_ on other platforms. Other platforms let you run an application…
Brad Campbell wrote 9 lines
Hans-Peter Diettrich wrote: > On Windows you can uncheck the option (see above), to get a GUI > application with an attached console. A very nice feature for debugging, not > available on most other platforms. Actually not _required_ on other platforms. Other platforms let you run an application from a console and witness its output should you so desire, without having to recompile the application with odd options.

I have same problem on WinCE when connect to database or load the language, the exception not raise to my customer, my application just not run, and there is no console for GUI at Windows CE.

Zaher Dirkey

Reply by email

Brad Campbell
to Hans-Peter Diettrich: Thanks, I didn't know that it's so easy. The same procedure should be possible on Windows?
Hans-Peter Diettrich wrote 13 lines
Brad Campbell schrieb: >> On Windows you can uncheck the option (see above), to get a GUI >> application with an attached console. A very nice feature for >> debugging, not available on most other platforms. > > Actually not _required_ on other platforms. Other platforms let you > run an application from a console and witness its output should you so > desire, without having to recompile the application with odd options. Thanks, I didn't know that it's so easy. The same procedure should be possible on Windows?

No, on Windows you need to compile the app as console mode to have it write anything to a console window, otherwise it just launches the application and returns you to the console prompt.

I had to debug some Win stuff recently, and as I've been lucky enough to have avoided it for many years now, this oddity caught me several times.

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Phil Hess
to Brad Campbell

With Windows if you need to output something to the console in a GUI app, you use OutputDebugString. This will output to the console when running the app under gdb.

Thanks.

-Phil

----- "Brad Campbell" wrote 38 lines
Hans-Peter Diettrich wrote: > Brad Campbell schrieb: > >>> On Windows you can uncheck the option (see above), to get a GUI >>> application with an attached console. A very nice feature for >>> debugging, not available on most other platforms. >> >> Actually not _required_ on other platforms. Other platforms let you >> run an application from a console and witness its output should you so >> desire, without having to recompile the application with odd options. > > Thanks, I didn't know that it's so easy. > > The same procedure should be possible on Windows? No, on Windows you need to compile the app as console mode to have it write anything to a console window, otherwise it just launches the application and returns you to the console prompt. I had to debug some Win stuff recently, and as I've been lucky enough to have avoided it for many years now, this oddity caught me several times. Brad -- Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email