removed the DEH symbol ({%).

added new experimental features
 - the signal method to the Error class for simplified error/exception handling
 - the catch method to the BlockContext for simplified error/exception catching instead of the full-fledged on:do
This commit is contained in:
hyunghwan.chung 2017-11-21 15:05:12 +00:00
parent b07cab3874
commit 6177cd6865
5 changed files with 67 additions and 49 deletions

View File

@ -354,4 +354,48 @@ extend Error
method(#primitive) asInteger.
method(#primitive) asCharacter.
method(#primitive) asString.
method signal
{
| exctx exblk retval actpos ctx |
exctx := (thisContext sender) findExceptionContext.
while (exctx notNil)
{
exblk := exctx findExceptionHandlerFor: (self class).
if (exblk notNil and: [actpos := exctx basicSize - 1. exctx basicAt: actpos])
{
exctx basicAt: actpos put: false.
[ retval := exblk value: self ] ensure: [ exctx basicAt: actpos put: true ].
thisContext unwindTo: (exctx sender) return: nil.
System return: retval to: (exctx sender).
}.
exctx := (exctx sender) findExceptionContext.
}.
## -----------------------------------------------------------------
## FATAL ERROR - no exception handler.
## -----------------------------------------------------------------
##thisContext unwindTo: nil return: nil.
##thisContext unwindTo: (Processor activeProcess initialContext) return: nil.
## TOOD: IMPROVE THIS EXPERIMENTAL BACKTRACE...
System logNl: '== BACKTRACE =='.
ctx := thisContext.
while (ctx notNil)
{
if (ctx class == MethodContext) { System logNl: (' ' & ctx method owner name & '>>' & ctx method name) }.
## TODO: include blockcontext???
ctx := ctx sender.
}.
System logNl: '== END OF BACKTRACE =='.
thisContext unwindTo: (thisProcess initialContext) return: nil.
('### ERROR NOT HANDLED #### ' & self class name & ' - ' & self asString) dump.
## TODO: debug the current process???? "
##Processor activeProcess terminate.
thisProcess terminate.
}
}

View File

@ -165,11 +165,11 @@ class(#pointer,#final,#limited) BlockContext(Context)
self primitiveFailed.
}
method ifTrue: aBlock
{
##^(self value) ifTrue: aBlock.
^if (self value) { aBlock value }.
}
method ifFalse: aBlock

View File

@ -6,7 +6,8 @@
##
class Exception(Apex)
{
var signalContext, handlerContext, messageText.
var signalContext, handlerContext.
var(#get) messageText.
(*
TODO: can i convert 'thisProcess primError' to a relevant exception?
@ -18,7 +19,6 @@ TODO: can i convert 'thisProcess primError' to a relevant exception?
}
*)
method(#class) signal
{
^self new signal
@ -34,23 +34,12 @@ TODO: can i convert 'thisProcess primError' to a relevant exception?
self.handlerContext := context.
}
method messageText
{
^self.messageText
}
method asString
{
^(self class name) & ' - ' & self.messageText.
}
(* TODO: remove this....
method __signal
{
self.signalContext := thisContext.
((thisContext sender) findExceptionContext) handleException: self.
}*)
method signal
{
| exctx exblk retval actpos ctx |
@ -62,8 +51,7 @@ TODO: can i convert 'thisProcess primError' to a relevant exception?
while (exctx notNil)
{
exblk := exctx findExceptionHandlerFor: (self class).
if (exblk notNil and:
[actpos := exctx basicSize - 1. exctx basicAt: actpos])
if (exblk notNil and: [actpos := exctx basicSize - 1. exctx basicAt: actpos])
{
self.handlerContext := exctx.
exctx basicAt: actpos put: false.
@ -180,7 +168,8 @@ extend Context
{
## -------------------------------------------------------------------
## <<private>>
## private: called by VM upon unwinding
## private: called by VM upon unwinding as well as by
## Exception<<signal and Error<<signal
## -------------------------------------------------------------------
| ctx stop eb pending_pos |
@ -277,7 +266,9 @@ extend MethodContext
## exc := self basicAt: i.
## if ((exception_class == exc) or: [exception_class inheritsFrom: exc]) { ^self basicAt: (i + 1) }.
##]
i := MethodContext.Index.FIRST_ON.
## start scanning from the position of the first parameter
i := MethodContext.Index.FIRST_ON.
while (i < size)
{
exc := self basicAt: i.
@ -372,6 +363,14 @@ thisContext isExceptionContext dump.
^self value.
}
method on: exc1 do: blk1 on: exc2 do: blk2 on: exc3 do: blk3
{
| exception_active |
<exception>
exception_active := true.
^self value.
}
method ensure: aBlock
{
| retval pending |
@ -394,6 +393,12 @@ thisContext isExceptionContext dump.
[ v := self value. pending := false. ] ensure: [ if (pending) { aBlock value } ].
^v.
}
method catch
{
^self on: Exception do: [:ex | ex ]
on: Error do: [:err | err ].
}
}
@ -440,10 +445,6 @@ class NotImplementedException(Exception)
{
}
class ErrorExceptionizationFailureException(Exception)
{
}
class InvalidArgumentException(Exception)
{
}
@ -452,14 +453,6 @@ class ProhibitedMessageException(Exception)
{
}
(*
pooldic ErrorToException
{
ErrorCode.EINVAL := InvalidArgumentException.
ErrorCode.ENOIMPL := NotImplementedException.
}
*)
extend Apex
{
method(#dual,#liberal) primitiveFailed(method)

View File

@ -1682,26 +1682,8 @@ retry:
break;
case '{': /* extension */
#if 0
SET_TOKEN_TYPE (moo, MOO_IOTOK_LBRACE);
goto single_char_token;
#else
SET_TOKEN_TYPE (moo, MOO_IOTOK_RETURN);
ADD_TOKEN_CHAR(moo, c);
GET_CHAR_TO (moo, c);
if (c == '@')
{
/* {@ */
TOKEN_TYPE(moo) = MOO_IOTOK_DEH_BLOCK; /* default exception handling block */
ADD_TOKEN_CHAR (moo, c);
}
else
{
unget_char (moo, &moo->c->lxc);
}
break;
#endif
case '}': /* extension */
SET_TOKEN_TYPE (moo, MOO_IOTOK_RBRACE);
goto single_char_token;

View File

@ -361,7 +361,6 @@ struct moo_iotok_t
MOO_IOTOK_HASHBRACK, /* #[ - byte array literal */
MOO_IOTOK_PERCPAREN, /* %( - array expression */
MOO_IOTOK_PERCBRACE, /* %{ - dictionary expression */
MOO_IOTOK_DEHBRACE, /* {% */
MOO_IOTOK_PERIOD,
MOO_IOTOK_COMMA,
MOO_IOTOK_SEMICOLON