Class Throwable

Direct Known Subclasses:
::xoexception::Error, ::xoexception::Exception,

Associated Test:

Class Throwable
superclass ::xotcl::Object,
Throwable is the base class for all objects that can be
 thrown in xoexception. Throwables are objects that are thrown
 with the Tcl "error" command.  Instead of throwing string
 errors, exception objects can be thrown that contain
 more information that an unformatted string. 

 To throw an exception use:

 error [ Throwable new "Some error has occured" ]

 This can be used with a catch statement:

 if [ catch {

     error [ Throwable new "error" ]

 } result ] {

     puts "Caught exception. Message is [ $result message ]"

 Throwable also provides some facilities to work with exceptions.

 isThrowable is used to determine if a catch-result is an 
 exception object or a unformatted string.

 Throwable isThrowable "some string"
 returns 0

 Throwable isThrowable [ Throwable new "error" ]

 returns 1

 extractMessage is used to get the message from an Throwable or
 from an unformatted string.

 if [ catch {

 #Some error happens here. It might throw an Throwable or an string.

 } result ] {
     #It doesnt matter if the result is a string or Throwable object.
     puts "[ Throwable extractMessage $result ]"

 try is an extension of catch that can catch certain types of 

 try {
     #Code that could possibly thrown an error.
     #The exceptions can be called in this block or
     #in procs within this block.
 } catch {Error e1} {
     #Handle the error here if the error thrown is of
     #type Error or a subclass of Error.
     #More specific exceptions must come first in 
     #the blocks as these blocks are queried in top-to-bottom
     #order. Error is a subclass of Throwable so any Error
     #instance is also an Throwable instance and would always
     #be handled by the next block.
 } catch {Throwable e2} {      
     #Handle the error here if the error thrown is of
     #type Throwable or a subclass of Throwable.
 } catch {error e3} {   
     #try/catch can also catch unformatted string errors.
     #Use the type "error" to catch string errors.
 } finally {                                 
     #Finally blocks are optional.  They are always called
     #after all of the catch blocks are called, and even if 
     #they are not called.
NameDefault ValueClassComment
message    ::xoexception::Throwable
 The message that is carried with the Throwable.
trace    ::xoexception::Throwable
 The stack trace that was recorded when the Throwable was created
init {{message ""}}   Constructor that creates a new Throwable object with a message
Methods from ::xotcl::Object
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
Instproc Detail


 Constructor that creates a new Throwable object with a message.
 The default message is blank.
init in ::xotcl::Object
  ::xoexception::Throwable instproc init {{message ""}}  {

        ::xotcl::my message $message
        ::xotcl::my trace [ ::xotcl::my stackTrace ]