GenericException.st
changeset 22641 b7e8988896dd
parent 22533 b809fa3426cc
child 22798 fbfb1f60ce4b
--- a/GenericException.st	Tue Mar 20 15:52:54 2018 +0100
+++ b/GenericException.st	Tue Mar 20 22:06:14 2018 +0100
@@ -226,7 +226,6 @@
     self raiseErrorString:messageText
 ! !
 
-
 !GenericException class methodsFor:'accessing'!
 
 errorString
@@ -380,6 +379,35 @@
     ^ self name
 
     "Created: / 10-02-2011 / 12:28:51 / cg"
+!
+
+printBadExceptionHandler:badExceptionHandler in:aContext
+    "if anyone does:
+        [ xxx ] on: foo do:[ ... ]
+     with a bad foo (i.e. nil or not an Exception, ExceptionSet, Signal or HandlerSet
+     this method is called to print a warning.
+     Usually, this happens when foo is misspelled or when porting code
+     from Squeak, and there is no such exception-class in ST/X.
+     A typical situation is:
+        [ xxx ] on: NetworkError do:[ ... ]
+    "
+
+    badExceptionHandler isNil ifTrue:[
+        'Block [warning]: nil Exception in on:do:on:do:-context' errorPrintCR.
+        'Block [warning]: the sender is: ' infoPrint. aContext sender errorPrintCR.
+    ] ifFalse:[
+        (badExceptionHandler isBehavior
+        and:[badExceptionHandler isLoaded not]) ifTrue:[
+            "If the exception class is still autoloaded,
+             it does not accept our exception. Raising the exception would load the class"
+            ^ nil
+        ].
+        'Block [warning]: non-Exception in on:do:on:do:-context' errorPrintCR.
+        'Block [warning]: the context is: ' infoPrint. aContext sender errorPrintCR.
+    ].
+    aContext fullPrintString errorPrintCR.
+    self breakPoint:#cg.
+    ^ nil.
 ! !
 
 !GenericException class methodsFor:'queries'!