comp.lang.ada
 help / color / mirror / Atom feed
From: sjw <simon.j.wright@mac.com>
Subject: Re: With Exceptions Disabled On Windows, How Can I Determine Where A Software Interrupt Occurs
Date: Tue, 20 Oct 2009 13:50:25 -0700 (PDT)
Date: 2009-10-20T13:50:25-07:00	[thread overview]
Message-ID: <48671690-8bdc-462c-9ccc-103a7a810476@l34g2000vba.googlegroups.com> (raw)
In-Reply-To: 4ade0003$0$966$ba4acef3@news.orange.fr

On Oct 20, 7:23 pm, Pascal Obry <pas...@obry.net> wrote:
> Le 20/10/2009 20:01, ChristopherL a écrit :
>
> > I'm looking for a compilable/working example on how to do this. For
> > example code to determine where a divide by zero occurs etc.
>
> With GNAT?
>
> Nothing, you should get something like this when running your application:
>
>     raised CONSTRAINT_ERROR : buf.adb:12 divide by zero
>
> > If I can't get the code what can you tell me?
>
> To have full backtrace and also check for overflow you should compile
> your application with -gnato and pass -E on the binder:
>
>     $ gnatmake prog -cargs -gnato -bargs -E

GNAT doesn't raise numeric overflow exceptions for plain floats,
though it will raise CE if you declare the right subtypes: this

with Ada.Text_IO; use Ada.Text_IO;
procedure Divide_By_Zero is
   subtype Flt is Float;
   function Div (Denominator, Numerator : Flt) return Flt is
   begin
      return Denominator / Numerator;
   end Div;
begin
   Put_Line (Float'Image (Div (1.0, 0.0)));
   Put_Line (Float'Image (Div (-1.0, 0.0)));
   Put_Line (Float'Image (Div (0.0, 0.0)));
end Divide_By_Zero;

outputs

$ ./divide_by_zero
 +Inf*******
-Inf*******
NaN********

but if you replace the declaration of Flt by

   subtype Flt is Float range Float'Range;

you get

raised CONSTRAINT_ERROR : divide_by_zero.adb:6 range check failed



  parent reply	other threads:[~2009-10-20 20:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7091f995-dd7e-4442-8ca5-158b83e50bec@x5g2000prf.googlegroups.com>
2009-10-20 18:23 ` With Exceptions Disabled On Windows, How Can I Determine Where A Software Interrupt Occurs Pascal Obry
2009-10-20 18:37   ` Dmitry A. Kazakov
2009-10-20 18:43     ` Pascal Obry
2009-10-20 19:04       ` Dmitry A. Kazakov
2009-10-21 10:53     ` Georg Bauhaus
2009-10-20 20:50   ` sjw [this message]
     [not found] <b0d7911b-cb10-4fb2-a977-da865b8b2001@u16g2000pru.googlegroups.com>
2009-10-20 19:31 ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox