throw()

Throws an exception without message, zero index, and void value.

throw(s)

Throws an exception with message given by string s, zero index, and void value.

throw(s, i)

Throws an exception with message given by string s, index given by integer i, and void value.

throw(s, i, v)

Throws an exception with message given by string s, index given by integer i, and value given by v.


See also try exception catch 


Example


f(x)={

   y = "hello";

   try {

      switch(x) {

         case 0: return 88;

         case 1: x = x+y;

            break;

         case 2: throw("This is a user exception");

         case 3: throw("This is a user exception", 788);

         case 4: throw("This is a user exception", 789, y);

         case 5: throw(3);

      }

   }

   catch {

      s = exception();

      println("Caught exception: ", s.what, "\nIndex is ", s.index, " object is ", s.value);

      return 99;

   }

}


f(0)

   88


f(1)

Caught exception: Binary operator "+" of a "integer" and a "string" is not implemented

Index is 0 object is void

   99


f(2)

Caught exception: This is a user exception

Index is 0 object is void

   99


f(3)

Caught exception: This is a user exception

Index is 788 object is void

   99


f(4)

Caught exception: This is a user exception

Index is 789 object is hello

   99


f(5)

Caught exception: Parameter number 1 passed to function "throw" is of type "integer".

It must be of type "string".

Index is 0 object is void

   99