Singularity : exception;
To be complete, here's the syntax for defining an exception, describing using BNF:
exception_declaration ::= defining_identifier_list ": exception;" defining_identifier_list ::= identifier { "," identifier }
Exception declarations are generally placed in a package declaration.
Raising an exception is easy, too - just use the raise statement. A raise statement is simply the keyword "raise" followed by the name of the exception. For example, to raise the "Singularity" exception defined above, just say:
raise Singularity;
The syntax in BNF is:
raise_statement ::= "raise" [ exception_name ] ";"
You'll notice that the exception_name is optional; we'll discuss what that means in the next section.
Which of the following would define an exception named No_Safety_Net?
![]() |
![]() |
![]() |
---|
David A. Wheeler (dwheeler@ida.org)