An atomic concept for error handler. Creating this concept with its
constructor (create) is equal with launching an error. This error will
look for handlers (concepts and methods) to handle the error. If no
handlers, it will apply the default methods (the methods error or
warning). If no default (global) methods sets in concept, will show the
default error message. An error concept can have two types: error and
warning (plus one, the silent mode only for unit tests).
In the concept where you want to launch an error:
- Error.create( type, method, message) or
- Error.create( type, method, messase, concept) or
- Concept err = Error.create( type, method, message)
Can set an error handler concept (where to be a handler method):
.setErrorHandler( concept )
Can obtain the handler concept:
Concept handler = .getErrorHandler()
An error handler method look like this:
: anyHandlerMethod ( $err typeof Error ) [
#you can obtain the error message
StringConcept msg = .getMSG()
#you can set the error message
.setMSG( "everything" )
#you can obtain the error type (error or warning)
StringConcept msg = .getType()
#you can set the error type
.setType( "warning" )
#you can obtain the Concept passed over the constructor
Concept msg = .getConcept()]
Parameters: |
$type : | The error type |
$id : | The error handler method name |
$msg : | The error message |
|
Create the Error concept specifying the type, method name and error
message
Parameters: |
$type : | The error type |
$id : | The error handler method name |
$msg : | The error message |
$con : | Any Concept can passed here to handler |
|
Create the Error concept specifying the type, method name, error message
and an concept for handler.
In the handler method you can obtain the passed concept with this method.
define Test [
:handlerMethod($e typeof Error) [
print $e.getConcept
]
static : main ($args typeof Series) [
$con typeof Test
Test.setErrorHandler($con)
Error.create("error", "handlerMethod", "This is an error message.", $con)
]
]
-- the result is --
Test
Get the error type.
$err typeof Error
$err.setType("Warning")
print $err.getType
-- the result is --
Warning
Get the error message.
$err typeof Error
$err.setMSG("This is an ERROR message")
print $err.getMSG
-- the result is --
This is an ERROR message
Prints the specified message to the output stream adding
an EOL at the end.
Error.println("This is a test message.")
-- the result is --
This is a test message.
Prints the specified message to the output stream.
Error.print("This is a test message.")
-- the result is --
This is a test message.
Set the error message.
$err typeof Error
$err.setMSG("This is an ERROR message")
print $err.getMSG
-- the result is --
This is an ERROR message
Set the error type.
$err typeof Error
$err.setType("Warning")
print $err.getType
-- the result is --
Warning