Catch and re-throw is very expensive (especially if you are bubbling it up - don't code everything this way as it will compound through your code and you'll log it many times). Essentially, make sure it is a true exception and not part of normal expected behaviour. You'd also usually target the specific exceptions you need to deal with as Darren says, rather than the top level class, but we all understand life is sometimes too short and it gets left to be done 'later'!
From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Darren Neimke Sent: Wednesday, 6 October 2010 6:37 AM To: ozmoss@ozmoss.com Subject: RE: Variable declared but never used AND passing Guid as an attribute parameter I'll answer the first question Paul... it's not 'best practice' to go around catching exceptions and doing nothing with them. At the very least, you would log the exception details out somewhere and then rethrow, e.g.: catch (Exception ex) { myLogger.Log(ex) ; throw ; } In the case where you know that a certain exception might get thrown and you want to handle it explicitly, then only create Catch blocks for those exceptions. In the case of the code that you've shown, the documetnation tells you that the Font constructor will only ever thrown an ArgumentException, so that's what should be getting caught here, not the general System.Exception: http://msdn.microsoft.com/en-us/library/164w6x6z.aspx Darren Neimke darren.nei...@live.com _____ From: paul.no...@ceosyd.catholic.edu.au To: ozmoss@ozmoss.com Date: Wed, 6 Oct 2010 09:24:37 +1100 Subject: Variable declared but never used AND passing Guid as an attribute parameter Hi all, Please excuse my .NET ignorance but I'm coming at all this from a PHP background and am trying really, really hard to become a real developer. J I'm debugging someone else's code and would greatly appreciate any explanations for the following. 1. The variable 'ex' is declared but never used. This is caused by the following try/catch block but I don't think removing the variable is suitable in this case as it looks like it's supposed to be a fallback in the event the declared font is not available. Would this be better suited to an if/else or switch statement? Any suggestions. private void SetFamilyName(string familyName) { // If the named font is not installed, default to a system font. try { Font font = new Font(this.familyName, 12F); this.familyName = familyName; font.Dispose(); } catch (Exception ex) { this.familyName = System.Drawing.FontFamily.GenericSerif.Name; } } 2. The other question surrounds the (odd?) passing of a Guid from the fldtype XML to the code behind pages. I have never seen this before and don't really understand why it's here at all. Is it required for InteropServices or something? Fldtype_myfield.xml <Field Name="FieldTypeClass">5b05e101-608a-4265-aa9b-b7932707ac0a</Field> Is this correct? I usually put the full class name and assembly info here. myField.cs and myFieldControl.cs namespace Org.SharePoint.fieldName { [CLSCompliant(false)] [Guid("5b05e101-608a-4265-aa9b-b7932707ac0a")] No idea whether the CLSCompliant bit is needed either. :\ Regards, Paul -- Online Developer/Administrator, ICT Projects Team CEO Sydney _______________________________________________ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
_______________________________________________ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss