Jump to content
Mohammad Atikur Rhaman

"Divided by zero" exception

Recommended Posts

im come from DBase III Plus and Clipper Summer 87... any error was not an exception, but  a fact! 

(I jumped MSX Basic)😁

Edited by programmerdelphi2k

Share this post


Link to post

99% off-top here.

 

My project is not throwing a "Divide by zero" exception. Delphi 12.

The project is not a DLL.

The project was created from scratch file->new project.

 

Why do I have to set a so-called "exception mask" when I didn't have to in the previous version?

What else, along with the masks, should I set to get it back to how it should work by default?

You shouldn't talk about masks, but about the fact that it creates UB. This is not what Pascal should do.

 

Share this post


Link to post
46 minutes ago, Joseph MItzen said:

I'll bite... what other programming languages don't raise an exception when you divide by zero?

C++, Swift to name some.

 

Interoperability with code written in other languages (although this is not a language issue per-se) was one of the main reasons why exceptions are masked now, as such code would commonly expect masked exceptions. So you had to do mask/unmask at every call to such code which then caused issues in threading as Delphi FPCR functions were not thread-safe at all.

 

For instance: https://stackoverflow.com/q/9472265/

Share this post


Link to post

It wasn't enough for them to have undefined behavior in C that you decided to put it in Pascal?

OLE objects are not common use.

Don't know anything about thread-safety and mask at every call. Why not mask once if you need this?

Again, whose fault is it that "FPCR" (what's that?) is still not thread-safe?

 

Okay, customers will no longer complain about "zero divide" exceptions, but they also will not complain about "not catched" exceptions either, because they will not notice them, for the time being. SO it's a win-win strategy.

Share this post


Link to post
2 hours ago, terran said:

Don't know anything about thread-safety and mask at every call. Why not mask once if you need this?

 

Consider when code using unmasked exceptions calls code in a DLL that uses masked exceptions. The floating-point control register (FPCR) needs to be set to mask exceptions just before the call then unmask them on return.  The functions provided by Delphi to update the FPCR are not thread safe so they can botch it. 

 

For the non-FMX Windows platform Delphi code ran with unmasked floating-point exceptions on by default before the recent change. Most C/C++/C# code runs with them masked. This meant the above scenario happened when calling into most non-Delphi DLLs from Delphi. 

Share this post


Link to post
5 hours ago, terran said:

OLE objects are not common use.

I doubt this statement is remotely true. 

Share this post


Link to post
18 hours ago, terran said:

OLE objects are not common use.

Also not only OLE object but any dll.

Look at how many dll's an app loads:

 

0b520000 security.dll                    10.0.19041.1        C:\WINDOWS\SYSTEM32
50a00000 atlthunk.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
59e80000 ntshrui.dll                     10.0.19041.4355     C:\WINDOWS\SYSTEM32
59f90000 PhotoMetadataHandler.dll        10.0.19041.4355     C:\WINDOWS\system32
5a000000 DropboxExt.76.0.dll             1.0.76.0            C:\Program Files (x86)\Dropbox\Client
5a6b0000 drivefsext.dll                  97.0.1.0            C:\Program Files\Google\Drive File Stream\97.0.1.0\x86
5bf80000 NetworkExplorer.dll             10.0.19041.4355     C:\WINDOWS\system32
5bfa0000 rdpendp.dll                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
5bff0000 MMDevApi.dll                    10.0.19041.4355     C:\WINDOWS\System32
5c060000 DevDispItemProvider.dll         10.0.19041.3636     C:\Windows\System32
5c0d0000 dlnashext.dll                   10.0.19041.4355     C:\Windows\System32
5c120000 twinapi.dll                     10.0.19041.4355     C:\Windows\System32
5c1b0000 davclnt.dll                     10.0.19041.3636     C:\WINDOWS\System32
5c1d0000 ntlanman.dll                    10.0.19041.4842     C:\WINDOWS\System32
5c290000 StructuredQuery.dll             7.0.19041.4355      C:\WINDOWS\System32
5c320000 uiautomationcore.dll            7.2.19041.4355      C:\Windows\System32
5c5a0000 tiptsf.dll                      10.0.19041.4355     C:\Program Files (x86)\Common Files\microsoft shared\ink
5c670000 DUser.dll                       10.0.19041.3636     C:\WINDOWS\SYSTEM32
5c6f0000 DUI70.dll                       10.0.19041.4355     C:\WINDOWS\SYSTEM32
60010000 bthprops.cpl                    10.0.19041.4355     C:\WINDOWS\SYSTEM32
60220000 browcli.dll                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
602c0000 dfscli.dll                      10.0.19041.1        C:\WINDOWS\System32
602d0000 thumbcache.dll                  10.0.19041.4355     C:\Windows\System32
60320000 Msftedit.DLL                    10.0.19041.4355     C:\WINDOWS\SYSTEM32
60a00000 apphelp.dll                     10.0.19041.4842     C:\WINDOWS\SYSTEM32
60b50000 Windows.Globalization.dll       10.0.19041.4355     C:\Windows\System32
60ca0000 bcp47mrm.dll                    10.0.19041.4355     C:\Windows\System32
64700000 LINKINFO.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
647b0000 c_g18030.dll                    10.0.19041.3636     C:\WINDOWS\system32
647f0000 dcomp.dll                       10.0.19041.4597     C:\WINDOWS\system32
64960000 d3d11.dll                       10.0.19041.4355     C:\WINDOWS\system32
650b0000 msxml6.dll                      6.30.19041.4355     C:\Windows\System32
65510000 twinapi.appcore.dll             10.0.19041.4597     C:\WINDOWS\system32
656b0000 d2d1.dll                        10.0.19041.4355     C:\WINDOWS\system32
65ea0000 dxgi.dll                        10.0.19041.4842     C:\WINDOWS\system32
65f70000 DAVHLPR.dll                     10.0.19041.3636     C:\WINDOWS\System32
66230000 drprov.dll                      10.0.19041.3636     C:\WINDOWS\System32
662c0000 IdnDL.dll                       10.0.19041.1        C:\WINDOWS\SYSTEM32
662d0000 c_iscii.dll                     10.0.19041.1        C:\WINDOWS\system32
66440000 globinputhost.dll               10.0.19041.4355     C:\WINDOWS\SYSTEM32
66630000 OneCoreCommonProxyStub.dll      10.0.19041.4597     C:\Windows\System32
66670000 dataexchange.dll                10.0.19041.4355     C:\WINDOWS\system32
66870000 explorerframe.dll               10.0.19041.4842     C:\WINDOWS\system32
66a50000 c_is2022.dll                    10.0.19041.3636     C:\WINDOWS\system32
66a60000 usp10.dll                       10.0.19041.3636     C:\WINDOWS\SYSTEM32
66bc0000 SHFolder.dll                    10.0.19041.1        C:\WINDOWS\SYSTEM32
66be0000 cscapi.dll                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
66c20000 wkscli.dll                      10.0.19041.3636     C:\WINDOWS\System32
66c40000 olepro32.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
66c60000 FaultRep.dll                    10.0.19041.4355     C:\WINDOWS\SYSTEM32
66cd0000 windowscodecs.dll               10.0.19041.4648     C:\WINDOWS\system32
66e50000 CoreUIComponents.dll            10.0.19041.3636     C:\WINDOWS\SYSTEM32
670d0000 CoreMessaging.dll               10.0.19041.4474     C:\WINDOWS\SYSTEM32
67170000 textinputframework.dll          10.0.19041.4651     C:\WINDOWS\SYSTEM32
67230000 DWrite.dll                      10.0.19041.4355     C:\WINDOWS\SYSTEM32
67440000 TextShaping.dll                                     C:\WINDOWS\SYSTEM32
674e0000 oledlg.dll                      10.0.19041.4355     C:\WINDOWS\SYSTEM32
67510000 msvcp110_win.dll                10.0.19041.3636     C:\WINDOWS\SYSTEM32
67580000 policymanager.dll               10.0.19041.4597     C:\WINDOWS\SYSTEM32
67c30000 SAMLIB.dll                      10.0.19041.3996     C:\WINDOWS\SYSTEM32
67d30000 amsi.dll                        10.0.19041.4355     C:\WINDOWS\SYSTEM32
67dc0000 Bcp47Langs.dll                  10.0.19041.4355     C:\Windows\System32
67eb0000 wintypes.dll                    10.0.19041.4717     C:\WINDOWS\SYSTEM32
68e00000 Windows.FileExplorer.Common.dll 10.0.19041.4842     C:\Windows\System32
6b970000 ncryptsslp.dll                  10.0.19041.3636     C:\WINDOWS\system32
6baa0000 cldapi.dll                      10.0.19041.3636     C:\Windows\System32
6bb30000 FLTLIB.DLL                      10.0.19041.3636     C:\Windows\System32
6bb40000 schannel.dll                    10.0.19041.4597     C:\WINDOWS\System32
6bbc0000 propsys.dll                     7.0.19041.4355      C:\WINDOWS\SYSTEM32
6bca0000 ncrypt.dll                      10.0.19041.4412     C:\WINDOWS\SYSTEM32
6bd10000 NTASN1.dll                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
6bd40000 mskeyprotect.dll                10.0.19041.3636     C:\WINDOWS\SYSTEM32
6bd50000 edputil.dll                     10.0.19041.4355     C:\WINDOWS\SYSTEM32
6bd70000 urlmon.dll                      11.0.19041.4894     C:\WINDOWS\SYSTEM32
6c7f0000 webio.dll                       10.0.19041.3636     C:\WINDOWS\SYSTEM32
6cfc0000 WINNSI.DLL                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
6d840000 WINSTA.dll                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
6dca0000 rasadhlp.dll                    10.0.19041.3636     C:\Windows\System32
6de60000 Fwpuclnt.dll                    10.0.19041.4123     C:\WINDOWS\SYSTEM32
6dfc0000 MpOav.dll                       4.18.24080.9        C:\ProgramData\Microsoft\Windows Defender\Platform\4.18.24080.9-0\X86
6e110000 iertutil.dll                    11.0.19041.4894     C:\Windows\System32
6f650000 srvcli.dll                      10.0.19041.3636     C:\Windows\System32
6f870000 DEVOBJ.dll                      10.0.19041.4355     C:\WINDOWS\SYSTEM32
6f8a0000 sxs.dll                         10.0.19041.3636     C:\WINDOWS\SYSTEM32
6f930000 dhcpcsvc6.dll                   10.0.19041.3636     C:\WINDOWS\SYSTEM32
6fb60000 ntmarta.dll                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
71d50000 hid.dll                         10.0.19041.3636     C:\WINDOWS\SYSTEM32
71d60000 profapi.dll                     10.0.19041.4355     C:\WINDOWS\SYSTEM32
71d80000 dhcpcsvc.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
71da0000 dwmapi.dll                      10.0.19041.4355     C:\WINDOWS\SYSTEM32
71dd0000 Wldp.dll                        10.0.19041.4780     C:\WINDOWS\SYSTEM32
71e00000 CRYPTBASE.DLL                   10.0.19041.3636     C:\WINDOWS\SYSTEM32
71fe0000 windows.storage.dll             10.0.19041.4894     C:\WINDOWS\SYSTEM32
72600000 dbgcore.DLL                     10.0.19041.4355     C:\WINDOWS\SYSTEM32
73420000 MSASN1.dll                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
734c0000 kernel.appcore.dll              10.0.19041.3758     C:\WINDOWS\SYSTEM32
734d0000 NETUTILS.DLL                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
735a0000 samcli.dll                      10.0.19041.3636     C:\WINDOWS\SYSTEM32
735c0000 DPAPI.DLL                       10.0.19041.3636     C:\WINDOWS\SYSTEM32
73670000 SSPICLI.DLL                     10.0.19041.4239     C:\WINDOWS\SYSTEM32
73be0000 winmm.dll                       10.0.19041.3636     C:\WINDOWS\SYSTEM32
73c10000 WININET.dll                     11.0.19041.4717     C:\WINDOWS\SYSTEM32
74070000 winhttp.dll                     10.0.19041.4717     C:\WINDOWS\SYSTEM32
74240000 oleacc.dll                      7.2.19041.3636      C:\WINDOWS\SYSTEM32
742a0000 uxtheme.dll                     10.0.19041.4894     C:\WINDOWS\system32
74420000 comctl32.dll                    6.10.19041.4355     C:\WINDOWS\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_a865f0c28672571c
74630000 mswsock.dll                     10.0.19041.3636     C:\WINDOWS\system32
74690000 gdiplus.dll                     10.0.19041.4597     C:\WINDOWS\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.4597_none_d954b6f7e1016a2a
74800000 winspool.drv                    10.0.19041.4597     C:\WINDOWS\SYSTEM32
74880000 iphlpapi.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
748c0000 netapi32.dll                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
748e0000 SECUR32.DLL                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
748f0000 MPR.dll                         10.0.19041.3636     C:\WINDOWS\SYSTEM32
74990000 msimg32.dll                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
749a0000 dbghelp.dll                     10.0.19041.3996     C:\WINDOWS\SYSTEM32
74b30000 wsock32.dll                     10.0.19041.1        C:\WINDOWS\SYSTEM32
74c30000 DNSAPI.dll                      10.0.19041.4474     C:\WINDOWS\SYSTEM32
74cc0000 USERENV.dll                     10.0.19041.4355     C:\WINDOWS\System32
74cf0000 version.dll                     10.0.19041.3636     C:\WINDOWS\SYSTEM32
74d00000 WTSAPI32.DLL                    10.0.19041.3636     C:\WINDOWS\SYSTEM32
75000000 msvcp_win.dll                   10.0.19041.3636     C:\WINDOWS\System32
75080000 KERNELBASE.dll                  10.0.19041.4894     C:\WINDOWS\System32
752c0000 MSCTF.dll                       10.0.19041.4842     C:\WINDOWS\System32
75510000 bcryptPrimitives.dll            10.0.19041.3636     C:\WINDOWS\System32
75570000 SHLWAPI.dll                     10.0.19041.4355     C:\WINDOWS\System32
755c0000 sechost.dll                     10.0.19041.4597     C:\WINDOWS\System32
75640000 setupapi.dll                    10.0.19041.4355     C:\WINDOWS\System32
75a80000 coml2.dll                       10.0.19041.4355     C:\WINDOWS\System32
75ae0000 oleaut32.dll                    10.0.19041.3636     C:\WINDOWS\System32
75c10000 comdlg32.dll                    10.0.19041.4355     C:\WINDOWS\System32
75d20000 ws2_32.dll                      10.0.19041.3636     C:\WINDOWS\System32
75d90000 bcrypt.dll                      10.0.19041.3636     C:\WINDOWS\System32
75db0000 Normaliz.dll                    10.0.19041.3636     C:\WINDOWS\System32
75dc0000 crypt32.dll                     10.0.19041.4894     C:\WINDOWS\System32
75ec0000 clbcatq.dll                     2001.12.10941.16384 C:\WINDOWS\System32
75f40000 advapi32.dll                    10.0.19041.4597     C:\WINDOWS\System32
75fc0000 user32.dll                      10.0.19041.4894     C:\WINDOWS\System32
76160000 ole32.dll                       10.0.19041.4355     C:\WINDOWS\System32
76250000 NSI.dll                         10.0.19041.3636     C:\WINDOWS\System32
76260000 combase.dll                     10.0.19041.4894     C:\WINDOWS\System32
764e0000 msvcrt.dll                      7.0.19041.3636      C:\WINDOWS\System32
765a0000 WINTRUST.dll                    10.0.19041.4780     C:\WINDOWS\System32
765f0000 ucrtbase.dll                    10.0.19041.3636     C:\WINDOWS\System32
76710000 psapi.dll                       10.0.19041.3636     C:\WINDOWS\System32
76720000 KERNEL32.DLL                    10.0.19041.4842     C:\WINDOWS\System32
76810000 shell32.dll                     10.0.19041.4894     C:\WINDOWS\System32
76e50000 win32u.dll                      10.0.19041.4894     C:\WINDOWS\System32
76e70000 shcore.dll                      10.0.19041.4522     C:\WINDOWS\System32
76f00000 GDI32.dll                       10.0.19041.4474     C:\WINDOWS\System32
76f30000 IMM32.DLL                       10.0.19041.4474     C:\WINDOWS\System32
76f60000 gdi32full.dll                   10.0.19041.4894     C:\WINDOWS\System32
77050000 cfgmgr32.dll                    10.0.19041.3996     C:\WINDOWS\System32
77090000 IMAGEHLP.DLL                    10.0.19041.3636     C:\WINDOWS\System32
770b0000 RPCRT4.dll                      10.0.19041.4597     C:\WINDOWS\System32
77180000 ntdll.dll                       10.0.19041.4842     C:\WINDOWS\SYSTEM32

 

Share this post


Link to post
19 hours ago, terran said:

Again, whose fault is it that "FPCR" (what's that?) is still not thread-safe?

That's Embarcadero's fault. They've known how to fix this for at least 10 years, and my patched version of the RTL fixes it.

 

That said, the real issue isn't really a language issue. It's a platform issue. It all stems from the way floating point is implemented on x86 and x86-64 hardware.

  • Like 4

Share this post


Link to post
16 hours ago, Brian Evans said:

This meant the above scenario happened when calling into most non-Delphi DLLs from Delphi. 

Or when calling into a Delphi DLL. 

Share this post


Link to post

As a side note.

unit Vcl.Edge;

....

initialization
  FSetExceptMask(femALLEXCEPT);

SHDocVw, Vcl.Edge and other units set the mask.

If someone is using TWebWrowser for example all exceptions are masked but not on all machines is so and I do not have time now to investigate why.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×