User Tools

Site Tools


exceptions

Dana supports runtime exceptions, but implements them differently to many other languages. In particular, exceptions in Dana are considered as advisory to an observer. Exceptions cannot be “caught” or otherwise detected to have happened at runtime, and never result in system termination. Instead, exceptions are inherently contained to the function in which they occur, causing that particular function to abort and return the default value of its return type (0 for int, 0.0 for dec, false for bool, null for arrays, objects and data types, etc.).

We adopt this advisory model for three reasons. The first is that, because Dana supports the dynamic loading of code at runtime, having a system in which un-caught exceptions may cause system termination would make for potentially very unstable programs. The second is that, because we separate interfaces from implementations, it's likely that different implementations of an interface may cause different exceptions to be fired in the case of errors. Instead of needing to annotate functions declared in interfaces with every possible exception type that might need to be caught, we instead treat exceptions as advisory and non-disruptive to program execution. Third, we believe that programs should be inherently robust; allowing general language-level exceptions (such as array index out of bounds) to result in large portions of a program aborting, or exiting entirely, creates inherent fragility requiring extensive defensive programming to be employed for robustness.

Exceptions in Dana are thrown as follows:

int MyInterface:myFunction(char param[])
   {
   if (param == null)
      throw new Exception("parameter was empty")
 
   return param.arrayLength
   }

The result of triggering this exception is that the function returns immediately at the “throw” line, and automatically returns the default value of its return type, which is 0 in this case. No further effects of the exception are experienced by the running program.

Dana has only one “kind” of exception (there are no sub-types) and the text given with the exception is intended purely for human (or other monitoring) interpretation about issues occurring in the program.

exceptions.txt · Last modified: 2017/06/29 16:47 by barryfp

Page Tools