3

Again a Delphi newbie question. Is there a standard way of specifying the exceptions raised by a method (I have googled this but can't seem to find anything on the topic beyond the basics of handling exceptions).

In other words is there a standard way of saying "my function/procedure can throw this specific exception" in the function/procedure signature (I assume no). What is then the best practice to let the client of your API know which kind of exceptions will be raised by a given procedure/method

Arioch 'The
  • 15,799
  • 35
  • 62
BigONotation
  • 4,406
  • 5
  • 43
  • 72
  • 3
    Only languages like Java force developers to specify that in code, but in fact that only brings more trouble. Languages such as C# allows exceptions to be specified in comments/documentation. So for Delphi, I think you can only leave specific documentation. – Lex Li May 31 '17 at 02:14
  • And languages like C++ have even moved away from specifying the exact exceptions in code. – Remy Lebeau May 31 '17 at 03:00
  • 1
    [An interesting read](http://www.artima.com/intv/handcuffs.html) on the subject by Anders Hejlsberg – Lieven Keersmaekers May 31 '17 at 05:05
  • Another interesting read comes from Java co-developer Martin Odersky: in his post-Java language the "checked exceptions" feature got removed as practically harming, see http://steshaw.org/posts/2007/06/18/exceptions-checked-or-not/index.html . Also read https://softwareengineering.stackexchange.com/questions/177806/decision-for-unchecked-exceptions-in-scala and http://www.scala-lang.org/old/node/8787 and http://www.scala-lang.org/old/node/1939 (no any follow up!) and – Arioch 'The May 31 '17 at 07:46
  • https://groups.google.com/forum/#!topic/javaposse/XnrpS0nXDSw%5B51-75%5D read comment by phil swenson 18.08.09 – Arioch 'The May 31 '17 at 07:52

1 Answers1

6

There is no syntax in the Delphi pascal language to do what you are asking for. All you can do is list the possible exceptions in the function/procedure/method's documentation.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • thanks for the answer. One more point: what happens to an unhandled exception? I know that in the case of of GUI app it is somehow handled by the delphi runtime and it displays a dialog. But what happens say in the case of a server app such as an ISAPI extension? – BigONotation May 31 '17 at 11:16
  • Depends on how the ISAPI DLL is implemented. – David Heffernan May 31 '17 at 11:49
  • Basically an ISAPI extension would be a TWebModule instance, which is loaded in IIS. If you don't handle the exception, will it crash IIS? Hopefully not! :) – BigONotation May 31 '17 at 14:30