Sorry for the slow response. Perhaps you've already worked it out, but
anyway a few options...
You "could" pass thisContext as a block parameter
initialize
errorBlock := [ :tPduError :aContext | Error signal:'Method: ' ,
aContext selector
asString , ' with result: ', tPduError item asString ].
pduDestruct
result = T_PDU_ERROR PDU_STATUS_NOERROR ifFalse: [ errorBlock
value: result value: thisContext
------------------------------------
But rather I suggest a better option is to separate this logic into its own
error class...
Error subclass: #PduError
... instanceVariables: 'result selector'
PduError class >> result: aResult context: aContext
^ self new initializeResult: aResult selector: aContext selector
asString
PduError >> initializeResult: aResult selector: selectorString
result := aResult.
selector := selectorString
PduEror>>messageText
as you like - refer to other implementors for example
PduError>>printOn:
as you like - refer to other implementors for example
pduDestruct
| result |
result := call ffiPDUDestruct.
result = T_PDU_ERROR PDU_STATUS_NOERROR ifFalse: [
(PduError result: aResult context: thisContext) signal ]
cheers -ben
On Sat, 27 Jun 2020 at 22:56, ASAM <[email protected]> wrote:
> Hello,
> I would like to output the method name as a string in case of an error.
>
> what I've already done is this: (with thisContext selector asString)
>
> pduDestruct
> | result |
> result := call ffiPDUDestruct.
> result = T_PDU_ERROR PDU_STATUS_NOERROR
> ifFalse: [ Error signal:'Method: ' , thisContext selector asString , '
> with
> result: ', result item asString ]
>
>
> but now I use it more often. And wanted to rebuild it like that.
>
> initialize
> errorBlock := [ :tPduError | Error signal:'Method: ' , thisContext
> selector
> asString , ' with result: ', tPduError item asString ].
>
>
> pduDestruct
> | result |
> result := call ffiPDUDestruct.
> result = T_PDU_ERROR PDU_STATUS_NOERROR ifFalse: [ errorBlock
> value: result
> ]
>
>
> but that doesn't work because "this Context selector toString" now returns
> 'initialize'.
>
> Can someone give me a hint how to solve this?
> Is "thisContext selector asString" the only way to get the name of the
> method at runtime?
>
> Thanks in advance.
>