Skip to content
Benedict Allen edited this page Nov 15, 2015 · 1 revision

Exception Class

The Exception class is the OOP counterpart to the Sheets Exception system.

Constructor

Exception( string exception_type, data, number level = 1 )

level is the level at which to start the stack traceback, and works like Lua error levels.

Properties

name

Exception.name - string

The name of the exception.

data

Exception.data

The data thrown with the exception.

trace

Exception.trace - table

The table containing the traceback of the exception.

Methods

getTraceback()

string traceback = Exception:getTraceback( string initial = "", string delimiter = "\n" )

Returns a string representation of the traceback, with traces separated by the delimiter given, and beginning with initial.

string fmt = Exception:getDataAndTraceback( number indent = 1 )

Returns a string representation of the traceback and data combined. indent will indent the traceback portion.

tostring()

string e = Exception:tostring()

Return a string representation of the exception, including name, data, and traceback.

Static functions

thrown()

Exception last = Exception.thrown()

Returns the last thrown exception.

throw()

function Exception.throw( string name, data, number level = 1 )
function Exception.throw( Exception e )

Throws an exception.

try()

function(table) block = Exception.try( function f )

Returns a function to be called with a table of catches, so the following syntax is used:

Exception.try (f) {
    ...
}

catch()

function(function(Exception)) catch = Exception.catch( string etype )
function(function(Exception)) catch = Exception.catch( Class etype )

Returns a function to be called with the handler for the exception type given. Usage:

Exception.try (f) {
    Exception.catch (etype) (handler);
}

default()

table catch = Exception.default( function handler )

Returns a table for use in the block of a try call. Usage:

Exception.try (f) {
    Exception.catch (etype) (handler);
    Exception.default (handler);
}

Clone this wiki locally