2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
## TODO: is it better to inherit from Object???
|
|
|
|
## or treat Exception specially like UndefinedObject or Class???
|
|
|
|
##
|
2017-01-06 09:53:40 +00:00
|
|
|
class Exception(Apex)
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-11-21 15:05:12 +00:00
|
|
|
var signalContext, handlerContext.
|
|
|
|
var(#get) messageText.
|
2016-06-26 15:03:12 +00:00
|
|
|
|
2017-05-04 05:22:45 +00:00
|
|
|
(*
|
|
|
|
TODO: can i convert 'thisProcess primError' to a relevant exception?
|
|
|
|
var(#class) primExceptTable.
|
|
|
|
|
|
|
|
method(#class) forPrimitiveError: no
|
|
|
|
{
|
|
|
|
^self.primExceptTable at: no
|
|
|
|
}
|
|
|
|
*)
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) signal
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^self new signal
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) signal: text
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^self new signal: text
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method handlerContext: context
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
self.handlerContext := context.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method asString
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
^(self class name) & ' - ' & self.messageText.
|
|
|
|
}
|
2017-12-03 17:08:04 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method signal
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-04-26 15:31:07 +00:00
|
|
|
| exctx exblk retval actpos ctx |
|
2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
self.signalContext := thisContext.
|
2017-01-05 10:16:04 +00:00
|
|
|
exctx := (thisContext sender) findExceptionContext.
|
2017-11-21 09:15:22 +00:00
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
##[exctx notNil] whileTrue: [
|
|
|
|
while (exctx notNil)
|
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
exblk := exctx findExceptionHandlerFor: (self class).
|
2017-11-21 15:05:12 +00:00
|
|
|
if (exblk notNil and: [actpos := exctx basicSize - 1. exctx basicAt: actpos])
|
2017-04-26 15:31:07 +00:00
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
self.handlerContext := exctx.
|
|
|
|
exctx basicAt: actpos put: false.
|
2017-04-26 15:31:07 +00:00
|
|
|
[ retval := exblk value: self ] ensure: [ exctx basicAt: actpos put: true ].
|
2017-01-05 10:16:04 +00:00
|
|
|
thisContext unwindTo: (exctx sender) return: nil.
|
2017-11-21 09:15:22 +00:00
|
|
|
System return: retval to: (exctx sender).
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2017-01-05 10:16:04 +00:00
|
|
|
exctx := (exctx sender) findExceptionContext.
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
## -----------------------------------------------------------------
|
|
|
|
## FATAL ERROR - no exception handler.
|
|
|
|
## -----------------------------------------------------------------
|
|
|
|
##thisContext unwindTo: nil return: nil.
|
2016-07-05 15:22:29 +00:00
|
|
|
##thisContext unwindTo: (Processor activeProcess initialContext) return: nil.
|
2017-04-26 15:31:07 +00:00
|
|
|
|
|
|
|
## TOOD: IMPROVE THIS EXPERIMENTAL BACKTRACE...
|
2017-05-12 04:15:09 +00:00
|
|
|
System logNl: '== BACKTRACE =='.
|
2017-04-26 15:31:07 +00:00
|
|
|
ctx := thisContext.
|
|
|
|
while (ctx notNil)
|
|
|
|
{
|
2017-05-12 04:15:09 +00:00
|
|
|
if (ctx class == MethodContext) { System logNl: (' ' & ctx method owner name & '>>' & ctx method name) }.
|
2017-04-26 15:31:07 +00:00
|
|
|
## TODO: include blockcontext???
|
|
|
|
ctx := ctx sender.
|
|
|
|
}.
|
2017-05-12 04:15:09 +00:00
|
|
|
System logNl: '== END OF BACKTRACE =='.
|
2017-04-26 15:31:07 +00:00
|
|
|
|
2016-07-05 15:22:29 +00:00
|
|
|
thisContext unwindTo: (thisProcess initialContext) return: nil.
|
2017-11-24 17:40:20 +00:00
|
|
|
('### EXCEPTION NOT HANDLED(Exception) #### ' & self class name & ' - ' & self messageText) dump.
|
2016-06-26 15:03:12 +00:00
|
|
|
## TODO: debug the current process???? "
|
2016-07-05 15:22:29 +00:00
|
|
|
|
|
|
|
##Processor activeProcess terminate.
|
|
|
|
thisProcess terminate.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method signal: text
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
self.messageText := text.
|
|
|
|
^self signal.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method pass
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
## pass the exception to the outer context
|
|
|
|
((self.handlerContext sender) findExceptionContext) handleException: self.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method return: value
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-11-21 09:15:22 +00:00
|
|
|
if (self.handlerContext notNil) { System return: value to: self.handlerContext }
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method retry
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
## TODO: verify if return:to: causes unnecessary stack growth.
|
2017-04-26 15:31:07 +00:00
|
|
|
if (self.handlerContext notNil)
|
|
|
|
{
|
2016-06-26 15:03:12 +00:00
|
|
|
self.handlerContext pc: 0.
|
2017-11-21 09:15:22 +00:00
|
|
|
System return: self to: self.handlerContext.
|
2017-04-26 15:31:07 +00:00
|
|
|
}
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method resume: value
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
## TODO: verify if return:to: causes unnecessary stack growth.
|
|
|
|
## is this correct???
|
2017-04-26 15:31:07 +00:00
|
|
|
| ctx |
|
|
|
|
if (self.signalContext notNil and: [self.handlerContext notNil])
|
|
|
|
{
|
2016-06-26 15:03:12 +00:00
|
|
|
ctx := self.signalContext sender.
|
|
|
|
self.signalContext := nil.
|
|
|
|
self.handlerContext := nil.
|
2017-11-21 09:15:22 +00:00
|
|
|
System return: value to: ctx.
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method resume
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^self resume: nil.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
##============================================================================
|
2017-01-06 09:53:40 +00:00
|
|
|
extend Context
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method isExceptionContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^false
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method isEnsureContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^false
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method ensureBlock
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
^nil
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method findExceptionContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
| ctx |
|
|
|
|
ctx := self.
|
2017-04-26 15:31:07 +00:00
|
|
|
while (ctx notNil)
|
|
|
|
{
|
|
|
|
if (ctx isExceptionContext) { ^ctx }.
|
2016-06-26 15:03:12 +00:00
|
|
|
ctx := ctx sender.
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
^nil
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method unwindTo: context return: retval
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
## -------------------------------------------------------------------
|
|
|
|
## <<private>>
|
2017-11-21 15:05:12 +00:00
|
|
|
## private: called by VM upon unwinding as well as by
|
|
|
|
## Exception<<signal and Error<<signal
|
2016-06-26 15:03:12 +00:00
|
|
|
## -------------------------------------------------------------------
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
| ctx stop eb pending_pos |
|
2016-07-04 15:36:10 +00:00
|
|
|
|
2016-06-26 15:03:12 +00:00
|
|
|
ctx := self.
|
|
|
|
stop := false.
|
2017-04-26 15:31:07 +00:00
|
|
|
until (stop)
|
|
|
|
{
|
2016-06-26 15:03:12 +00:00
|
|
|
eb := ctx ensureBlock.
|
2017-04-26 15:31:07 +00:00
|
|
|
if (eb notNil)
|
|
|
|
{
|
|
|
|
(* position of the temporary variable in the ensureBlock that indicates
|
|
|
|
* if the block has been evaluated *)
|
|
|
|
pending_pos := ctx basicSize - 1.
|
|
|
|
if (ctx basicAt: pending_pos)
|
|
|
|
{
|
|
|
|
ctx basicAt: pending_pos put: false.
|
2016-06-26 15:03:12 +00:00
|
|
|
eb value.
|
2017-04-26 15:31:07 +00:00
|
|
|
}
|
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
stop := (ctx == context).
|
|
|
|
ctx := ctx sender.
|
2016-07-01 16:31:47 +00:00
|
|
|
|
|
|
|
## stop ifFalse: [ stop := ctx isNil ].
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
^retval
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
##============================================================================
|
2017-11-21 09:15:22 +00:00
|
|
|
pooldic MethodContext.Preamble
|
|
|
|
{
|
|
|
|
## this must follow MOO_METHOD_PREAMBLE_EXCEPTION in moo.h
|
|
|
|
EXCEPTION := 13.
|
|
|
|
|
|
|
|
## this must follow MOO_METHOD_PREAMBLE_ENSURE in moo.h
|
|
|
|
ENSURE := 14.
|
|
|
|
}
|
|
|
|
|
|
|
|
pooldic MethodContext.Index
|
|
|
|
{
|
|
|
|
## [ value-block ] ensure: [ ensure-block ]
|
|
|
|
## assuming ensure block is a parameter the ensure: method to a
|
|
|
|
## block context, the first parameter is placed after the fixed
|
|
|
|
## instance variables of the method context. As MethodContex has
|
|
|
|
## instance variables, the ensure block must be at the 9th position
|
|
|
|
## which translates to index 8
|
|
|
|
ENSURE := 8.
|
|
|
|
|
|
|
|
|
|
|
|
## [ ... ] on: Exception: do: [:ex | ... ]
|
|
|
|
FIRST_ON := 8.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend MethodContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method isExceptionContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-11-21 09:15:22 +00:00
|
|
|
^self.method preambleCode == MethodContext.Preamble.EXCEPTION.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method isEnsureContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-11-21 09:15:22 +00:00
|
|
|
^self.method preambleCode == MethodContext.Preamble.ENSURE.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method ensureBlock
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-11-21 09:15:22 +00:00
|
|
|
^if (self.method preambleCode == MethodContext.Preamble.ENSURE) { self basicAt: MethodContext.Index.ENSURE } else { nil }
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method findExceptionHandlerFor: exception_class
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
(* find an exception handler block for a given exception class.
|
|
|
|
*
|
|
|
|
* for this to work, self must be an exception handler context.
|
|
|
|
* For a single on:do: call,
|
|
|
|
* self class specNumInstVars must return 8.(i.e.MethodContext has 8 instance variables.)
|
|
|
|
* basicAt: 8 must be the on: argument.
|
|
|
|
* basicAt: 9 must be the do: argument *)
|
2016-06-26 15:03:12 +00:00
|
|
|
|
2017-11-21 09:15:22 +00:00
|
|
|
| size exc i |
|
2017-04-26 15:31:07 +00:00
|
|
|
|
|
|
|
if (self isExceptionContext)
|
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
(* NOTE: the following loop scans all parameters to the on:do: method.
|
|
|
|
* if the on:do: method contains local temporary variables,
|
|
|
|
* those must be skipped from scanning. *)
|
|
|
|
|
|
|
|
size := self basicSize.
|
2017-11-21 09:15:22 +00:00
|
|
|
##8 priorTo: size by: 2 do: [ :i |
|
|
|
|
## exc := self basicAt: i.
|
|
|
|
## if ((exception_class == exc) or: [exception_class inheritsFrom: exc]) { ^self basicAt: (i + 1) }.
|
|
|
|
##]
|
2017-11-21 15:05:12 +00:00
|
|
|
|
|
|
|
## start scanning from the position of the first parameter
|
|
|
|
i := MethodContext.Index.FIRST_ON.
|
2017-11-21 09:15:22 +00:00
|
|
|
while (i < size)
|
|
|
|
{
|
2016-06-26 15:03:12 +00:00
|
|
|
exc := self basicAt: i.
|
2017-11-21 09:15:22 +00:00
|
|
|
if ((exception_class == exc) or: [exception_class inheritsFrom: exc])
|
|
|
|
{
|
|
|
|
^self basicAt: (i + 1).
|
|
|
|
}.
|
|
|
|
i := i + 2.
|
|
|
|
}.
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
^nil.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method handleException: exception
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
(* -----------------------------------------------------------------
|
|
|
|
* <<private>>
|
|
|
|
* called by Exception>>signal.
|
|
|
|
* this method only exists in the MethodContext and UndefinedObject.
|
|
|
|
* the caller must make sure that the receiver object is
|
|
|
|
* a method context or nil. Exception>>signal invokes this method
|
|
|
|
* only for an exception context which is a method context. it
|
|
|
|
* invokes it for nil when no exception context is found.
|
|
|
|
* ---------------------------------------------------------------- *)
|
2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
| excblk retval actpos |
|
|
|
|
|
2017-04-26 16:01:56 +00:00
|
|
|
(* position of the temporary variable 'exception_active' in MethodContext>>on:do.
|
2017-01-05 10:16:04 +00:00
|
|
|
* for this code to work, it must be the last temporary variable in the method. *)
|
2016-06-26 15:03:12 +00:00
|
|
|
actpos := (self basicSize) - 1.
|
|
|
|
|
|
|
|
excblk := self findExceptionHandlerFor: (exception class).
|
2017-04-26 15:31:07 +00:00
|
|
|
if (excblk isNil or: [(self basicAt: actpos) not])
|
|
|
|
{
|
2016-06-26 15:03:12 +00:00
|
|
|
## self is an exception context but doesn't have a matching
|
|
|
|
## exception handler or the exception context is already
|
|
|
|
## in the middle of evaluation.
|
|
|
|
^(self.sender findExceptionContext) handleException: exception.
|
2017-04-26 15:31:07 +00:00
|
|
|
}.
|
2016-06-26 15:03:12 +00:00
|
|
|
|
|
|
|
exception handlerContext: self.
|
|
|
|
|
2017-01-05 10:16:04 +00:00
|
|
|
(* -----------------------------------------------------------------
|
|
|
|
* if an exception occurs within an exception handler block,
|
|
|
|
* the search will reach this context again as the exception block
|
|
|
|
* is evaluated before actual unwinding. set the temporary variable
|
|
|
|
* in the exception context to mask out this context from the search
|
|
|
|
* list.
|
|
|
|
* ---------------------------------------------------------------- *)
|
2016-06-26 15:03:12 +00:00
|
|
|
self basicAt: actpos put: false.
|
|
|
|
[ retval := excblk value: exception ] ensure: [
|
|
|
|
self basicAt: actpos put: true
|
|
|
|
].
|
|
|
|
|
|
|
|
##(self.sender isNil) ifTrue: [ "TODO: CANNOT RETURN" ].
|
|
|
|
|
2017-01-05 10:16:04 +00:00
|
|
|
(* -----------------------------------------------------------------
|
|
|
|
* return to self.sender which is a caller of the exception context (on:do:)
|
|
|
|
* pass the first ensure context between thisContext and self.sender.
|
|
|
|
* [ [Exception signal: 'xxx'] ensure: [20] ] on: Exception do: [:ex | ...]
|
|
|
|
* ---------------------------------------------------------------- *)
|
2016-06-26 15:03:12 +00:00
|
|
|
thisContext unwindTo: self.sender return: nil.
|
2017-11-21 09:15:22 +00:00
|
|
|
System return: retval to: self.sender.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
##============================================================================
|
2017-01-06 09:53:40 +00:00
|
|
|
extend BlockContext
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method on: anException do: anExceptionBlock
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
| exception_active |
|
|
|
|
<exception>
|
|
|
|
|
2017-01-05 10:16:04 +00:00
|
|
|
(* -------------------------------
|
|
|
|
thisContext isExceptionContext dump.
|
2016-06-26 15:03:12 +00:00
|
|
|
(thisContext basicSize) dump.
|
|
|
|
(thisContext basicAt: 8) dump. ## this should be anException
|
|
|
|
(thisContext basicAt: 9) dump. ## this should be anExceptionBlock
|
|
|
|
(thisContext basicAt: 10) dump. ## this should be handlerActive
|
2017-01-05 10:16:04 +00:00
|
|
|
'on:do: ABOUT TO EVALUE THE RECEIVER BLOCK' dump.
|
|
|
|
---------------------------------- *)
|
2016-06-26 15:03:12 +00:00
|
|
|
exception_active := true.
|
|
|
|
^self value.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method on: exc1 do: blk1 on: exc2 do: blk2
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
| exception_active |
|
|
|
|
<exception>
|
|
|
|
exception_active := true.
|
|
|
|
^self value.
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:05:12 +00:00
|
|
|
method on: exc1 do: blk1 on: exc2 do: blk2 on: exc3 do: blk3
|
|
|
|
{
|
|
|
|
| exception_active |
|
|
|
|
<exception>
|
|
|
|
exception_active := true.
|
|
|
|
^self value.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method ensure: aBlock
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-04-26 15:31:07 +00:00
|
|
|
| retval pending |
|
2016-06-26 15:03:12 +00:00
|
|
|
<ensure>
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
pending := true.
|
2016-06-26 15:03:12 +00:00
|
|
|
retval := self value.
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
(* the temporary variable 'pending' may get changed
|
|
|
|
* during evaluation for exception handling.
|
|
|
|
* it gets chagned in Context>>unwindTo:return: *)
|
|
|
|
if (pending) { pending := false. aBlock value }.
|
2016-06-26 15:03:12 +00:00
|
|
|
^retval
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method ifCurtailed: aBlock
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-04-26 15:31:07 +00:00
|
|
|
| v pending |
|
|
|
|
pending := true.
|
|
|
|
[ v := self value. pending := false. ] ensure: [ if (pending) { aBlock value } ].
|
2016-06-26 15:03:12 +00:00
|
|
|
^v.
|
|
|
|
}
|
2017-11-21 15:05:12 +00:00
|
|
|
|
|
|
|
method catch
|
|
|
|
{
|
|
|
|
^self on: Exception do: [:ex | ex ]
|
|
|
|
on: Error do: [:err | err ].
|
|
|
|
}
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##============================================================================
|
2017-01-09 09:11:36 +00:00
|
|
|
class PrimitiveFailureException(Exception)
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
2017-05-11 14:59:20 +00:00
|
|
|
var errcode.
|
|
|
|
|
|
|
|
method(#class) withErrorCode: code
|
|
|
|
{
|
|
|
|
^(self new) errorCode: code; yourself.
|
|
|
|
}
|
|
|
|
|
|
|
|
method signal
|
|
|
|
{
|
|
|
|
self.errcode := thisProcess primError.
|
|
|
|
^super signal
|
|
|
|
}
|
|
|
|
|
|
|
|
method errorCode
|
|
|
|
{
|
|
|
|
^self.errcode
|
|
|
|
}
|
|
|
|
|
|
|
|
method errorCode: code
|
|
|
|
{
|
|
|
|
self.errcode := code
|
|
|
|
}
|
2017-01-05 10:16:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 09:11:36 +00:00
|
|
|
class NoSuchMessageException(Exception)
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class IndexOutOfRangeException(Exception)
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class SubclassResponsibilityException(Exception)
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-09 09:11:36 +00:00
|
|
|
class NotImplementedException(Exception)
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-09 09:11:36 +00:00
|
|
|
class InvalidArgumentException(Exception)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-19 16:46:44 +00:00
|
|
|
class ProhibitedMessageException(Exception)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend Apex
|
|
|
|
{
|
2017-05-09 15:48:44 +00:00
|
|
|
method(#dual,#liberal) primitiveFailed(method)
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
2017-05-11 14:59:20 +00:00
|
|
|
| a b msg ec ex |
|
2017-05-09 15:48:44 +00:00
|
|
|
|
2017-05-16 02:04:18 +00:00
|
|
|
(* since method is an argument, the caller can call this method
|
|
|
|
* from a context chain where the method context actually doesn't exist.
|
|
|
|
* when a primitive method is defined using the #primitive method,
|
|
|
|
* the VM invokes this primtiveFailed method without creating
|
|
|
|
* the context for the primitive method.
|
|
|
|
* method(#primitive) xxx.
|
|
|
|
* method(#primitive) xxx { <primitive: #_xxx> ^self primitiveFailed(thisContext method). }
|
|
|
|
* in the former definition, primitiveFailed is called without
|
|
|
|
* an activate context for the method xxx if the primitive fails.
|
|
|
|
* on the other handle, in the latter definition, the context
|
|
|
|
* for the method is activated first before primitiveFailed is
|
|
|
|
* invoked. in the context chain, the method for xxx is found.
|
|
|
|
*)
|
|
|
|
|
2017-05-09 15:48:44 +00:00
|
|
|
(*System logNl: 'Arguments: '.
|
|
|
|
a := 0.
|
2017-05-08 16:00:55 +00:00
|
|
|
b := thisContext vargCount.
|
|
|
|
while (a < b)
|
|
|
|
{
|
2017-05-09 15:48:44 +00:00
|
|
|
System logNl: (thisContext vargAt: a) asString.
|
2017-05-08 16:00:55 +00:00
|
|
|
a := a + 1.
|
2017-05-09 15:48:44 +00:00
|
|
|
}.*)
|
2017-05-16 02:04:18 +00:00
|
|
|
|
2017-05-11 14:59:20 +00:00
|
|
|
ec := thisProcess primError.
|
2017-05-16 02:04:18 +00:00
|
|
|
msg := thisProcess primErrorMessage.
|
|
|
|
if (msg isNil) { msg := ec asString }.
|
2017-05-11 14:59:20 +00:00
|
|
|
if (method notNil) { msg := msg & ' - ' & (method owner name) & '>>' & (method name) }.
|
2017-05-16 02:04:18 +00:00
|
|
|
|
2017-12-03 17:08:04 +00:00
|
|
|
### TODO: convert an exception to a more specific one depending on the error code.
|
|
|
|
###if (ec == Error.Code.ERANGE) { self index: index outOfRange: (self basicSize) }
|
|
|
|
### elsif (ec == Error.Code.EPERM) { self messageProhibited: method name }
|
|
|
|
### elsif (ec == Error.Code.ENOIMPL) { self subclassResponsibility: method name }.
|
|
|
|
|
2017-05-16 02:04:18 +00:00
|
|
|
(PrimitiveFailureException (* in: method *) withErrorCode: ec) signal: msg.
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
method(#dual) doesNotUnderstand: message_name
|
2016-06-26 15:03:12 +00:00
|
|
|
{
|
|
|
|
## TODO: implement this properly
|
2017-04-26 15:31:07 +00:00
|
|
|
| class_name |
|
|
|
|
class_name := if (self class == Class) { self name } else { self class name }.
|
|
|
|
NoSuchMessageException signal: (message_name & ' not understood by ' & class_name).
|
2016-06-26 15:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
method(#dual) index: index outOfRange: ubound
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
IndexOutOfRangeException signal: 'Out of range'.
|
|
|
|
}
|
2016-06-26 15:03:12 +00:00
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
method(#dual) subclassResponsibility: method_name
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
2017-01-09 09:11:36 +00:00
|
|
|
SubclassResponsibilityException signal: ('Subclass must implement ' & method_name).
|
2017-01-05 10:16:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
method(#dual) notImplemented: method_name
|
2017-01-09 09:11:36 +00:00
|
|
|
{
|
2017-04-26 15:31:07 +00:00
|
|
|
| class_name |
|
|
|
|
class_name := if (self class == Class) { self name } else { self class name }.
|
|
|
|
NotImplementedException signal: (method_name & ' not implemented by ' & class_name).
|
2017-01-09 09:11:36 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 15:31:07 +00:00
|
|
|
method(#dual) messageProhibited: method_name
|
2017-04-19 16:46:44 +00:00
|
|
|
{
|
2017-04-26 15:31:07 +00:00
|
|
|
| class_name |
|
|
|
|
class_name := if (self class == Class) { self name } else { self class name }.
|
|
|
|
ProhibitedMessageException signal: (method_name & ' not allowed for ' & class_name).
|
2017-04-19 16:46:44 +00:00
|
|
|
}
|
2017-01-05 10:16:04 +00:00
|
|
|
}
|