Hi Joe, The Function that you showed me - I'm having a bit of a problem with it. I have a global module called methods and I placed the function in there with the method signature as shown, but it shows a little bug symbol and the status bar message is "Error: there is no class with this name".
I have a feeling that I should actually be creating a subclass of RuntimeException (but what do I call this?), and somehow overriding its Name property. But I'm stumped as to how to do this. Ian. -- On 24 Feb 2007, at 7:30 pm, Joe Huber wrote: > At 7:03 PM +0000 2/24/07, Ian Piper wrote: >> I am trying to bullet-proof my application as far as possible and >> wanted to put Exception handlers in all of my methods. I have >> found that the Exceptions block in any method that calls quit gets >> fired, which surprised me rather. Why would this happen? > > RB uses an EndException to quit your program. So you need to be > careful to only catch exceptions you're prepared to handle. RB also > uses a ThreadEndException to kill threads, so be sure to avoid > those too. > >> Also, is there a way for the Exception block to report the type of >> Exception. I could do >> >> Exception err >> if err isA [whatever]Exception then >> ... >> >> but then I'd need to add else clauses for all types of Exception - >> rather ungainly. Is there a toString or similar type of method >> somewhere that lets me pick up an error type String or Integer to >> report in a log-file or error message? I tried str(err) but this >> causes a type mismatch Exception (ironically enough). > > You can handle a particular kind of exception by specifying the > exception type. > > Exception err as NilObjectException > > To get the name of the exception for logging purposes I wrote an > extension method to the runtime exception class. (included below) > > Also be careful about adding exception handlers to long methods. > There's a bug where they aren't called in Windows and MacIntel > builds. You wind up in the App.UnhandledException event instead. > http://www.realsoftware.com/feedback/viewreport.php?reportid=tsztqlsf > > Regards, > Joe Huber > > > Function Name(Extends err as RuntimeException) As string > if err ISA AssertionException then > return "AssertionException" > elseif err ISA FunctionNotFoundException then > return "FunctionNotFoundException" > elseIf err ISA IllegalCastException then > return "IllegalCastException" > elseIf err ISA InvalidParentException then > return "InvalidParentException" > elseIf err ISA KeyChainException then > return "KeyChainException" > elseIf err ISA KeyNotFoundException then > return "KeyNotFoundException" > elseIf err ISA NilObjectException then > return "NilObjectException" > elseIf err ISA OLEException then > return "OLEException" > elseIf err ISA OutOfBoundsException then > return "OutOfBoundsException" > elseIf err ISA OutOfMemoryException then > return "OutOfMemoryException" > elseIf err ISA RbScriptAlreadyRunningException then > return "RbScriptAlreadyRunningException" > elseIf err ISA RegExException then > return "RegExException" > elseIf err ISA RegistryAccessErrorException then > return "RegistryAccessErrorException" > elseIf err ISA ShellNotRunningException then > return "ShellNotRunningException" > elseIf err ISA SOAPException then > return "SOAPException" > elseIf err ISA SpotlightException then > return "SpotlightException" > elseIf err ISA StackOverflowException then > return "StackOverflowException" > elseIf err ISA ThreadAlreadyRunningException then > return "ThreadAlreadyRunningException" > elseIf err ISA TypeMismatchException then > return "TypeMismatchException" > elseIf err ISA UnsupportedFormatException then > return "UnsupportedFormatException" > elseIf err ISA XMLDOMException then > return "XMLDOMException" > elseIf err ISA XMLException then > return "XMLException" > elseIf err ISA XMLReaderException then > return "XMLReaderException" > else > return "Unknown exception type" > end if > > End Function > > _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
