I am trying to enable this mode, as per manual:
https://wiki.freepascal.org/Exceptions
By default exceptions are disabled. You can opt in by using the ObjFPC or DELPHI Compiler Mode, or adding -Sx to the compiler commandline.
So my question is, where exactly to enable this -Sx or {$mode objfpc} in code?
Adding
-Sx is misleading as that will be reset upon a
$mode directive. So it's better to use
$mode objfpc or
$mode delphi inside your units and your program file. This directive is best placed in front of the
uses-clause as the templates provided by Lazarus generate.
I expecting to not to see anymore errors like SIGSEV, but more informative text as indicated in the manual:
Processor-level interrupts like SIGSEGV or SIGFPU, which normally translate to run-time errors, are also changed to exceptions. For example, run-time error 200 (division by zero) becomes EDivByZero or EZeroDivide, while run-time error 216 (a general protection fault) becomes EAccessViolation.
My main goal is to see errors with extended text, if there is other ways, please advise.
The mode directive (or the command line parameter) only enables the
raise keyword as well as the
try … except and
try … finally blocks. To really catch exceptions you need to use the
SysUtils unit at least once in your program so that the hooks that convert runtime errors to sub classes of
Exception (which is declared in
SysUtils as well) are set up correctly.