From b4fff86a37d2f9474503eb0ba7d1acab514c0657 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Sep 2019 09:40:00 -0700 Subject: [PATCH] clean up PrintRoots2. --- prada2012/ch02/print_roots2.adb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/prada2012/ch02/print_roots2.adb b/prada2012/ch02/print_roots2.adb index e47ed1c..12807df 100644 --- a/prada2012/ch02/print_roots2.adb +++ b/prada2012/ch02/print_roots2.adb @@ -1,11 +1,13 @@ -- print_roots2 demonstrates runtime exceptions. with Ada.Text_IO; with Ada.Float_Text_IO; +with Ada.Numerics; with Ada.Numerics.Generic_Elementary_Functions; -procedure Print_Roots is +procedure Print_Roots2 is use Ada.Text_IO; use Ada.Float_Text_IO; + use Ada.Numerics; package Numerics is new Ada.Numerics.Generic_Elementary_Functions(Float); use Numerics; X: Float; @@ -16,8 +18,15 @@ begin loop Get(X); exit when X = 0.0; - Put("Root of "); Put(X); Put(" is "); + begin + Put("Root of "); Put(X); Put(" is "); + exception + when Ada.Numerics.Argument_Error => + Put("not calculable: X must be >= 0"); + when Constraint_Error => + Put("not calculable: X must be >= 0"); + end; Put(Sqrt(X)); New_Line; end loop; -end Print_Roots; +end Print_Roots2;