2016-03-28 13:27:03 +00:00
|
|
|
|
2017-01-09 12:52:37 +00:00
|
|
|
#include 'Moo.moo'.
|
2016-03-28 13:27:03 +00:00
|
|
|
|
|
|
|
#################################################################
|
|
|
|
## MAIN
|
|
|
|
#################################################################
|
|
|
|
|
|
|
|
## TODO: use #define to define a class or use #class to define a class.
|
|
|
|
## use #extend to extend a class
|
|
|
|
## using #class for both feels confusing.
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend Apex
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend SmallInteger
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method getTrue: anInteger
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
^anInteger + 9999.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method inc
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
^self + 1.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class TestObject(Object)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-04-24 09:20:27 +00:00
|
|
|
var(#class) Q, R.
|
|
|
|
var(#classinst) a1, a2.
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class MyObject(TestObject)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main2
|
2016-04-30 05:56:35 +00:00
|
|
|
{
|
2016-06-24 14:29:43 +00:00
|
|
|
| k q |
|
2016-06-13 15:52:09 +00:00
|
|
|
'BEGINNING OF main2' dump.
|
2016-06-24 14:29:43 +00:00
|
|
|
k := [ 'this is test-011' dump. q := Exception signal: 'main2 screwed...'. q dump. 8888 dump. ]
|
2016-06-13 15:52:09 +00:00
|
|
|
on: Exception do: [ :ex |
|
|
|
|
'Exception occurred' dump.
|
|
|
|
ex messageText dump.
|
|
|
|
'Getting back to....' dump.
|
|
|
|
"ex return: 9999."
|
|
|
|
ex pass.
|
|
|
|
'AFTER RETURN' dump.
|
|
|
|
].
|
2016-05-01 13:49:36 +00:00
|
|
|
|
2016-06-24 14:29:43 +00:00
|
|
|
'k=>>> ' dump.
|
2016-05-01 13:49:36 +00:00
|
|
|
k dump.
|
2016-06-13 15:52:09 +00:00
|
|
|
'END OF main2' dump.
|
2016-05-01 13:49:36 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) raise_exception
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
|
|
|
Exception signal: 'bad exceptinon'.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test3
|
2016-05-01 13:49:36 +00:00
|
|
|
{
|
2016-05-03 10:10:28 +00:00
|
|
|
| k j g_ex |
|
2016-05-01 13:49:36 +00:00
|
|
|
j := 20.
|
|
|
|
k := [
|
|
|
|
'>>> TEST3 METHOD >>> ' dump.
|
|
|
|
j dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
(j < 25) ifTrue: [ | t |
|
2016-05-03 10:10:28 +00:00
|
|
|
t := Exception signal: 'bad exceptinon'. ## when resumed, t should get Exception, the leftover in the stack...
|
|
|
|
t signal: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'. ## so it should be ok to signal again..
|
|
|
|
##t := self raise_exception. ## when resumed, t should get 'self'
|
|
|
|
|
|
|
|
##g_ex retry. # You should not do these as the following 3 lines make things very complicated.
|
|
|
|
##g_ex signal.
|
|
|
|
##g_ex pass.
|
|
|
|
|
2016-05-02 13:50:42 +00:00
|
|
|
'RESUMED???' dump.
|
|
|
|
t dump.
|
|
|
|
j dump.
|
|
|
|
].
|
|
|
|
|
2016-05-01 13:49:36 +00:00
|
|
|
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
|
|
|
'JJJJJJJJJJJJJJ' dump.
|
2016-05-03 10:10:28 +00:00
|
|
|
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. g_ex := ex. ex resume. ].
|
2016-04-30 05:56:35 +00:00
|
|
|
|
|
|
|
k dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
'END OF TEST3' dump.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test4_1
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
|
|
|
| k j |
|
|
|
|
j := 20.
|
|
|
|
k := [
|
|
|
|
'>>> TEST4_1 METHOD >>> ' dump.
|
|
|
|
j dump.
|
|
|
|
(j < 25) ifTrue: [ | t |
|
|
|
|
##t := Exception signal: 'bad exceptinon'. ## when resume, t should get Exception.
|
|
|
|
t := self raise_exception. ## when resumed, t should get 'self'
|
|
|
|
'RESUMED???' dump.
|
|
|
|
t dump.
|
|
|
|
j dump.
|
|
|
|
].
|
|
|
|
|
|
|
|
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
|
|
|
'JJJJJJJJJJJJJJ' dump.
|
|
|
|
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. ex pass. ].
|
|
|
|
|
|
|
|
k dump.
|
|
|
|
'END OF TEST4_1' dump.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test4
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
|
|
|
'BEGINNING OF TEST4' dump.
|
|
|
|
[ self test4_1 ] on: Exception do: [:ex | 'Excepton in test4_1' dump. ex messageText dump. ex resume].
|
|
|
|
'END OF TEST4' dump.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test5
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
|
|
|
| k j |
|
|
|
|
'BEGINNING OF TEST5' dump.
|
|
|
|
j := 20.
|
|
|
|
k := [
|
|
|
|
'>>> TEST5 BLOCK >>> ' dump.
|
|
|
|
j dump.
|
|
|
|
(j < 25) ifTrue: [ | t |
|
|
|
|
##t := Exception signal: 'bad exceptinon'. ## when resume, t should get Exception.
|
|
|
|
t := self raise_exception. ## when resumed, t should get 'self'
|
|
|
|
].
|
|
|
|
|
|
|
|
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
|
|
|
'JJJJJJJJJJJJJJ' dump.
|
|
|
|
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. ex retry. ].
|
|
|
|
|
|
|
|
k dump.
|
|
|
|
'END OF TEST5' dump.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test11
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
|
|
|
## exception is raised in a new process. it can't be captured
|
|
|
|
## by an exception handler of a calling process.
|
|
|
|
## exception handling must not cross the process boundary.
|
2016-06-13 15:52:09 +00:00
|
|
|
'BEGINNING OF test11' dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
[
|
|
|
|
|p |
|
2016-06-24 14:29:43 +00:00
|
|
|
p := [ 'TEST11 IN NEW PROCESS' dump. Exception signal: 'Exception raised in a new process of test11'. ] newProcess.
|
2016-05-02 13:50:42 +00:00
|
|
|
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
|
2016-06-24 14:29:43 +00:00
|
|
|
p resume. ## resume the new process
|
|
|
|
] on: Exception do: [:ex | '---- EXCEPTION IN TEST11. THIS MUST NOT BE PRINTED----------' dump. ex messageText dump ].
|
2016-06-13 15:52:09 +00:00
|
|
|
'END OF test11' dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test12
|
2016-05-02 13:50:42 +00:00
|
|
|
{
|
2016-06-13 15:52:09 +00:00
|
|
|
'BEGINNING OF test12' dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
[
|
|
|
|
|p |
|
|
|
|
p := [
|
2016-06-13 15:52:09 +00:00
|
|
|
[ Exception signal: 'Exception in a new process of test12' ]
|
|
|
|
on: Exception do: [:ex |
|
2016-12-13 15:18:19 +00:00
|
|
|
('EXCEPTION CAUGHT...in test12 ==> ' & (ex messageText)) dump.
|
2016-06-13 15:52:09 +00:00
|
|
|
]
|
2016-05-02 13:50:42 +00:00
|
|
|
] newProcess.
|
|
|
|
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
|
|
|
|
p resume.
|
|
|
|
] on: Exception do: [:ex | 'EXCEPTION ----------' dump. ex messageText dump ].
|
2016-06-13 15:52:09 +00:00
|
|
|
'END OF test12' dump.
|
2016-04-30 05:56:35 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2016-05-02 13:50:42 +00:00
|
|
|
|
2016-04-30 05:56:35 +00:00
|
|
|
'>>>>> BEGINNING OF MAIN' dump.
|
|
|
|
|
2016-06-13 15:52:09 +00:00
|
|
|
[ self main2 ] on: Exception do: [ :ex |
|
|
|
|
'EXCEPTION CAUGHT IN MAIN....' dump.
|
|
|
|
ex messageText dump.
|
2016-06-24 14:29:43 +00:00
|
|
|
##ex pass.
|
2016-06-13 15:52:09 +00:00
|
|
|
'Returning back to where the exception has signalled in main2...' dump.
|
2016-06-24 14:29:43 +00:00
|
|
|
##ex resume.
|
|
|
|
ex resume: 'RESUMED WITH THIS STRING'.
|
2016-06-13 15:52:09 +00:00
|
|
|
].
|
2016-05-01 13:49:36 +00:00
|
|
|
|
|
|
|
'##############################' dump.
|
2016-05-02 13:50:42 +00:00
|
|
|
## self test3.
|
|
|
|
## self test4.
|
|
|
|
|
2016-05-03 10:10:28 +00:00
|
|
|
## self test5.
|
2016-05-07 01:37:44 +00:00
|
|
|
self test11.
|
2016-05-02 13:50:42 +00:00
|
|
|
## self test12.
|
2016-06-13 15:52:09 +00:00
|
|
|
## 100 timesRepeat: ['>>>>> END OF MAIN' dump].
|
2016-05-02 13:59:28 +00:00
|
|
|
|
2016-05-07 01:37:44 +00:00
|
|
|
|
|
|
|
"(Exception isKindOf: Apex) dump.
|
|
|
|
(Exception isMemberOf: Apex) dump.
|
|
|
|
(Exception isMemberOf: Class) dump.
|
|
|
|
(1 isMemberOf: SmallInteger) dump.
|
|
|
|
(1 isKindOf: Integer) dump.
|
|
|
|
(1 isKindOf: Class) dump.
|
|
|
|
(1 isKindOf: Apex) dump.
|
|
|
|
(Exception isKindOf: Class) dump.
|
|
|
|
(Exception isKindOf: Apex) dump.
|
|
|
|
(Exception isKindOf: Object) dump.
|
|
|
|
(Exception isKindOf: (Apex new)) dump.
|
|
|
|
(Exception isKindOf: (Object new)) dump."
|
|
|
|
|
|
|
|
|
2016-05-03 10:10:28 +00:00
|
|
|
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@' dump.
|
2016-05-02 13:59:28 +00:00
|
|
|
## the following line(return:to:) must cause primitive failure...
|
2016-05-07 01:37:44 +00:00
|
|
|
##[ Processor return: 10 to: 20. ] on: Exception do: [:ex | ex messageText dump].
|
2016-05-03 10:10:28 +00:00
|
|
|
|
|
|
|
##[ Processor return: 10 to: 20. ]
|
|
|
|
## on: PrimitiveFailureException do: [:ex | 'PRIMITIVE FAILURE CAUGHT HERE HERE HERE' dump]
|
|
|
|
## on: Exception do: [:ex | ex messageText dump].
|
2016-05-02 13:59:28 +00:00
|
|
|
|
2016-06-24 14:29:43 +00:00
|
|
|
'SLEEPING FOR 10 seconds ....' dump.
|
2017-11-05 16:47:13 +00:00
|
|
|
System sleepForSecs: 10.
|
2016-06-24 14:29:43 +00:00
|
|
|
|
2016-04-30 05:56:35 +00:00
|
|
|
'>>>>> END OF MAIN' dump.
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
}
|