705 ! ! |
705 ! ! |
706 |
706 |
707 !Signal methodsFor:'save evaluation'! |
707 !Signal methodsFor:'save evaluation'! |
708 |
708 |
709 catch:aBlock |
709 catch:aBlock |
710 "evaluate the argument, aBlock. |
710 "evaluate the argument, aBlock. |
711 If the receiver-signal is raised during evaluation, abort |
711 If the receiver-signal is raised during evaluation, abort |
712 the evaluation and return true; otherwise return false. |
712 the evaluation and return true; otherwise return false. |
713 This is the catch & throw mechanism found in other languages, |
713 This is the catch & throw mechanism found in other languages, |
714 where the returned value indicates if an exception occured." |
714 where the returned value indicates if an exception occured." |
715 |
715 |
716 |raiseOccurred| |
716 |raiseOccurred| |
717 |
717 |
718 raiseOccurred := false. |
718 raiseOccurred := false. |
719 self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
719 self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
720 ^ raiseOccurred |
720 ^ raiseOccurred |
721 |
721 |
722 " |
722 " |
723 Object messageNotUnderstoodSignal catch:[ |
723 Object messageNotUnderstoodSignal catch:[ |
724 123 size open |
724 123 size open |
725 ] |
725 ] |
726 " |
726 " |
|
727 ! |
|
728 |
|
729 deferAfter:aBlock |
|
730 "evaluate the argument, aBlock. |
|
731 Ignore the receiver-signal during evaluation - i.e. simply continue, |
|
732 but remember if the signal was raised. |
|
733 After the block evaluation, finally raise the signal - if it was raised in the block. |
|
734 If the signal is raised multiple times, only the first raises parameter is remembered, |
|
735 and only a single raise is performed after the blocks evaluation. |
|
736 |
|
737 Deferring makes sense for some signals, such as UserInterrupt or AbortSignal, |
|
738 which must occasionally be delayed temprarily until a save place is reached |
|
739 (especially when packages are sent across a communication channel, and you dont want |
|
740 partial packages to be generated by user interruptions)." |
|
741 |
|
742 |raisedSignal parameter result| |
|
743 |
|
744 self handle:[:ex | |
|
745 raisedSignal isNil ifTrue:[ |
|
746 raisedSignal := ex signal. |
|
747 parameter := ex parameter. |
|
748 ]. |
|
749 ex proceedWith:nil |
|
750 ] do:[ |
|
751 result := aBlock value. |
|
752 ]. |
|
753 raisedSignal notNil ifTrue:[ |
|
754 "/ the signal was raised during the execution |
|
755 "/ above. Raise it now (delayed). |
|
756 raisedSignal raiseWith:parameter. |
|
757 ]. |
|
758 ^ result |
|
759 |
|
760 " |
|
761 UserInterrupt deferAfter:[ |
|
762 UserInterrupt raiseWith:'hello' |
|
763 ] |
|
764 " |
727 ! |
765 ! |
728 |
766 |
729 handle:handleBlock do:aBlock |
767 handle:handleBlock do:aBlock |
730 "evaluate the argument, aBlock. |
768 "evaluate the argument, aBlock. |
731 If the receiver-signal is raised during evaluation, |
769 If the receiver-signal is raised during evaluation, |
804 |
842 |
805 "Modified: / 25.7.1999 / 19:43:40 / stefan" |
843 "Modified: / 25.7.1999 / 19:43:40 / stefan" |
806 ! |
844 ! |
807 |
845 |
808 ignoreIn:aBlock |
846 ignoreIn:aBlock |
809 "evaluate the argument, aBlock. |
847 "evaluate the argument, aBlock. |
810 Ignore the receiver-signal during evaluation - i.e. simply continue. |
848 Ignore the receiver-signal during evaluation - i.e. simply continue. |
811 This makes only sense for some signals, such as UserInterrupt |
849 This makes only sense for some signals, such as UserInterrupt |
812 or AbortSignal, because continuing after an exception without any cleanup |
850 or AbortSignal, because continuing after an exception without any cleanup |
813 often leads to followup-errors." |
851 often leads to followup-errors." |
814 |
852 |
815 ^ self handle:[:ex | ex proceedWith:nil] do:aBlock. |
853 ^ self handle:[:ex | ex proceedWith:nil] do:aBlock. |
816 |
854 |
817 " |
855 " |
818 Object messageNotUnderstoodSignal ignoreIn:[ |
856 Object messageNotUnderstoodSignal ignoreIn:[ |
819 123 size open |
857 123 size open |
820 ] |
858 ] |
821 " |
859 " |
822 ! ! |
860 ! ! |
823 |
861 |
824 !Signal class methodsFor:'documentation'! |
862 !Signal class methodsFor:'documentation'! |
825 |
863 |
826 version |
864 version |
827 ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.85 2001-11-16 15:18:54 cg Exp $' |
865 ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.86 2002-02-15 12:59:12 cg Exp $' |
828 ! ! |
866 ! ! |