|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Exception.ToString()Exception.ToString() method? I'm writing Custom Exception classes and want to ensure that mine will be consistent (as far as Logging goes) with those defined in the Framework (particularly where Exceptions are nested). So far, I've pulled mscorlib apart and rummaged around the IL Code therein, and come up with this ... Public Overrides Function ToString() As String Dim sRC As String _ = Me.GetType().ToString() & ": " & Me.Message If Not (Me.InnerException Is Nothing) Then sRC &= " ---> " & Me.InnerException.ToString() _ & Environment.NewLine & " " _ & System.Environment.GetResourceString( "Exception_EndOfInnerExceptionStack" ) End If sRC &= Environment.NewLine & " " & Me.StackTrace Return sRC End Function .... but the GetResourceString bit falls flat on its face and, to be honest, I'm not entirely sure what it should be doing! TIA, Phill W. Phill,
| Can anyone supply me with the code (C# or VB) that lies within the I use this article for reference on Exceptions:| Exception.ToString() method? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp08162001.asp | ... but the GetResourceString bit falls flat on its face and, to be My local copy of MSDN only indicates .NET Compact Framework 2.0 (no mention | honest, I'm not entirely sure what it should be doing! of other varieties of the framework). Which indicates to me that the function is only available on the compact version for its limited support of resources... Normally in VB 2005 (.NET 2.0) I add a new resource file (.resx) to my project, then use My.Resources to access it. For example if I add the string to the Resources page of the project Properties I can: Dim s As String = My.Resources.Exception_EndOfInnerExceptionStack Similar if I add Exceptions.resx to my VB project, with a string named EndOfInnerExceptionStack, I can: Dim s As String = My.Resources.Exceptions.EndOfInnerExceptionStack I normally group my resources into common resource files. For example Exceptions.resx would have all my exception text. FWIW: String.Format is useful for text in resource files... -- Exceptions.resx: FileNotFound = "The file {0} was not found in folder {1}" -- SomeWhere.vb Dim theFileName As String = ... Dim theFolderName As String = ... Dim s As String = String.Format(My.Resources.Exceptions.FileNotFound, theFileName, theFolderName) Then when it gets translated into a foriegn language the order of the markers can be changed: -- Exceptions.xx.resx: FileNotFound = "{1} does not contain {0}" -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message news:e6u140$euu$1@yarrow.open.ac.uk... | Can anyone supply me with the code (C# or VB) that lies within the | Exception.ToString() method? | | I'm writing Custom Exception classes and want to ensure that mine will | be consistent (as far as Logging goes) with those defined in the | Framework (particularly where Exceptions are nested). | | So far, I've pulled mscorlib apart and rummaged around the IL Code | therein, and come up with this ... | | Public Overrides Function ToString() As String | Dim sRC As String _ | = Me.GetType().ToString() & ": " & Me.Message | | If Not (Me.InnerException Is Nothing) Then | sRC &= " ---> " & Me.InnerException.ToString() _ | & Environment.NewLine & " " _ | & System.Environment.GetResourceString( | "Exception_EndOfInnerExceptionStack" ) | End If | sRC &= Environment.NewLine & " " & Me.StackTrace | Return sRC | End Function | | ... but the GetResourceString bit falls flat on its face and, to be | honest, I'm not entirely sure what it should be doing! | | TIA, | Phill W. |
|||||||||||||||||||||||