File exception_demo.icn

Summary

Demonstration of the exception package

Author: Steve Wampler (sbw@tapestry.tucson.az.us)

This file is in the public domain.

Demonstration of exception handling. A call with any numeric argument other than three runs without Exception. Any non-numeric argument throws a NumException (locally defined) while a call with the argument 3 throws an Exception (base class for all Exceptions).

The result of calling:

    ExceptionDemo 1 2 3 4 a 6
is:
    x is '1'.
    x is '2'.
    Exception: bad value of 3:
        g [ExceptionDemo.icn:96]
        f [ExceptionDemo.icn:80]
        main [ExceptionDemo.icn:56]
    
    x is '4'.
    NumException: 'a' is not a number:
        g [ExceptionDemo.icn:93]
        f [ExceptionDemo.icn:80]
        main [ExceptionDemo.icn:56]
    
    x is '6'.

Classes:
NumException

Procedures:
f, g, main

Imports:
exception

This file is part of the (main) package.

Source code.

Details
Procedures:

f(i)

Parameter:
i
- arbitrary value

Simple function that outputs the result of another function. Used to show that exception handling is a true 'throw'.


g(i)

Parameter:
i
- arbitrary value
Returns:
i if numeric(i) ~= 3
Throws:
NumException
if argument is not numeric
Exception
if argument is 3

Simple function that performs (meaningless) work but can throw two different types of Exceptions.


main(args)



This page produced by UniDoc on 2021/04/15 @ 23:59:54.