0

In .Net, it is common practice during development to implement an interface gradually, so that not all interface functions are implemented for the first few rounds of development. Such an example would look like this in C#:

public string FutureGetString()
{
    // Not developed yet.
    throw new NotImplementedException();
}

However, I have not figured out how to do the equivalent in Ada. I would like to develop out the body for a package specification while leaving the door open on a few functions. Is there a way to throw an exception immediately? Right now, I have the following, which gives me a compiler error missing "return" statement in function body

function NotImplemented ( Input : Integer ) return Boolean is
begin
   raise Program_Error;
end;
Servy
  • 202,030
  • 26
  • 332
  • 449
theMayer
  • 15,456
  • 7
  • 58
  • 90

2 Answers2

5

I’ve seen this recommended (by a senior AdaCore engineer):

function NotImplemented ( Input : Integer ) return Boolean is
begin
   raise Program_Error;
   return NotImplemented (Input);
end;

I’d wondered whether the compiler might warn about infinite recursion, but no.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
4
function Not_Implemented (Input : in Integer) return Boolean is
   pragma Unreferenced (Input);
begin
   pragma Compile_Time_Warning (True, "Not_Implemented has not been implemented yet.");
   return raise Program_Error with "Not_Implemented has not been implemented yet.";
end Not_Implemented;
Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • My compiler does not seem to be happy with this at all - `missing expression in return from function`. – theMayer Nov 27 '17 at 20:28
  • `raise expressions` were added to Ada 2012 by the Technical Corrigendum 1, published in February 2016, so only up to date compilers will support this – egilhh Nov 27 '17 at 21:55
  • That code uses an Ada2012 feature, a raise expression ([ARM 11.3 (2.1)](http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-11-3.html#p2.1)), which can have any type ([(3.2)](http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-11-3.html#p3.2)) – Simon Wright Nov 27 '17 at 22:07
  • I think we are using gnat 6.4 - so it should theoretically support 2012. I must have it misconfigured somewhere. – theMayer Nov 27 '17 at 22:25
  • `-gnat2012` is usually how you select Ada 2012 with GNAT. GNAT doesn't seem to distinguish between Ada 2012 and Ada 2012/TC1. – Jacob Sparre Andersen Nov 28 '17 at 05:12
  • GCC 6.1.0 compiles without `-gnat2012` - but it warns that `Input` isn’t referenced. – Simon Wright Nov 28 '17 at 08:18
  • @SimonWright Thanks for the reminder. I've added two pragmas to complete the example. – Jacob Sparre Andersen Nov 28 '17 at 09:48