<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tucaz.blog.now() &#187; Arquitetura</title>
	<atom:link href="http://blog.tucaz.net/en/category/desenvolvimento/arquitetura-desenvolvimento/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tucaz.net</link>
	<description>Software architecture, agile and all that stuff that you can find everywhere</description>
	<lastBuildDate>Tue, 11 Jan 2011 21:00:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>(Portuguese) Lidando melhor com WCF &#8211; Ciclo de vida no cliente</title>
		<link>http://blog.tucaz.net/en/2010/02/23/lidando-com-wcf-ciclo-de-vida-no-cliente/</link>
		<comments>http://blog.tucaz.net/en/2010/02/23/lidando-com-wcf-ciclo-de-vida-no-cliente/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:02:31 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[channelfactory]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=415</guid>
		<description><![CDATA[</t>]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2010/02/23/lidando-com-wcf-ciclo-de-vida-no-cliente/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Basic stuff: handling exceptions in .NET</title>
		<link>http://blog.tucaz.net/en/2009/07/21/basic-stuff-handling-exceptions-in-net/</link>
		<comments>http://blog.tucaz.net/en/2009/07/21/basic-stuff-handling-exceptions-in-net/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 18:19:09 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[handling]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=336</guid>
		<description><![CDATA[A simple guide on How to build proper exception handling in .NET.]]></description>
			<content:encoded><![CDATA[<p>Last week we had a severe problem with exception handling in a project I&#8217;m working in. All the exceptions were being suppressed so we couldn&#8217;t know what was going on when some functionality didn&#8217;t work as we expected it to. This happened because a member of our team misinterpreted exception handling and put try/catch blocks in every method that he coded, but didn&#8217;t put any code in the catch block.</p>
<p>The  code spreaded everywhere looked like this:</p>
<pre name="code" class="csharp">try
{
     //Aplication logic goes here
}
catch (Exception ex)
{
     string error = ex.Message;
     //No re-throw or any exception handling code. Just this.
}</pre>
<p>As soon as we discovered the problem (and who was causing it), Max (a co-worker) wrote this &#8220;guide&#8221; and we made sure that everybody involved in the project read it. This is pretty basic stuff, but lot&#8217;s of people still don&#8217;t understand it. I&#8217;ll reproduce it below &#8220;as is&#8221; hoping that it will help you or someone you know <img src='http://blog.tucaz.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>What is the problem?</strong> Whenever an expection is trown, the code is trapping it in the catch block and it’s basically destroying it without proper handling and without escalete it in the stack (exception bubbling).</p>
<p><strong>Why is it a problem?</strong> This results in one of the worst maintenance nightmares. As the exception is being destroyed before it can be captured, bugs will become almost impossible to track in an QA/Production environment where debug is not available. Even in the development environment, chances are you’re only going to be able to track the root cause stepping through the code line by line.</p>
<p><strong>What to do?</strong> Unless you really have a need to do something specific with an exception, just let it escalete through the stack. Exceptions are usually handled at a higher level (like the user interface). Even when you need to do something with the exception, it will usally be necessary to re-throw it at the end of your code uless you’re coding the last layer (like a UI).</p>
<p>Here are some good practice examples:</p>
<p><em>Example 1:</em></p>
<pre name="code" class="csharp">public string GetUser(string userName)
{
    return new DAL().GetUser(userName);
}</pre>
<p>In this example the GetUser represents a intemediate layer code. As we don’t need any special handling, any exceptions resulting from the DAL method call will be simply escalted to the caller through the exception bubbling.</p>
<p><em>Example 2:</em></p>
<pre name="code" class="csharp">public string GetUser(string userName)
{
    try
    {
        return new DAL().GetUser(userName);
    }
    catch (Exception ex)
    {
        LogHelper.LogException(ex);
        throw;
    }
}</pre>
<p>In this case we do need to do something special about the exception. A good example would be a web service, where we should be loggin any errors, but re-throwing it to the caller so the application will be aware of it.</p>
<p><em>Example 3:</em></p>
<pre name="code" class="csharp">bool isValid = false;
try
{
    //Your application logic goes here
    isValid = true;
}
catch (DivideByZeroException)
{
    //Nothing needs to be done in case of an exception, this will kee the flag isValid as false
}</pre>
<p>This example illustrates a situation where you really need to destroy the exception. The Try/Catch block is being used exclusively to set a flag that depends on the result of an operation that might throw an exception, which would mean the status is invalid. Please note three important things:</p>
<p>a) In this case it is fundamental to add a comment to the Catch block in order to let your intention clear.</p>
<p>b) As you’re not planning to do anything special with the exception, a “catch(DivideByZeroException)” syntax is enough, since you won’t need to assign the exception to a local variable (which would generate a compilation warning about an unused variable). e.g.: catch (DivideByZeroException ex).</p>
<p>c) In this type of scenario you’re looking for a specific exception, so make sure you’re catching only that specific type of exception and let anything else bubble up (meaning, do not use “catch { }”). Also, when catching a specific exception, there’s no need for adding extra catch for the generic exception, anything else will automatically bubble up:</p>
<pre name="code" class="csharp">catch (DivideByZeroException)
{
    //Nothing needs to be done in case of an exception, this will kee the flag isValid as false
}
catch //There’s no need for this block
{
    throw;
}</pre>
<p><strong>Issue:</strong> You re-throw the exception using the “throw Exception” syntax:</p>
<p><strong>What is the problem?</strong> This resets the exception stack trace.</p>
<p><strong>Why is it a problem?</strong> The stack trace is lost and higher levels will perceive the error as being generated by your code. The main issue is the fact that it won’t allow you to track the root cause of the exception.</p>
<p><strong>What to do?</strong> The correct syntax to re-throw an exception is to simple state “throw” in your code, this way the stack trace is preserved.</p>
<pre name="code" class="csharp">try
{
    //Application logic goes here
}
catch (Exception ex)
{
    LogHelper.LogException(ex);
    throw;
}</pre>
<p>What if you need to generate a custom exception? Same issue with the stack trace. In this case the Exception constructor provides a parameter for the inner exception that must be used:</p>
<pre name="code" class="csharp">try
{
    //Application logic goes here
}
catch (Exception ex)
{
    LogHelper.LogException(ex);
    throw new Exception("My custom message", ex);
}</pre>
<p><strong>Issue:</strong> Unnecessary use of a Catch block when all you need is to get some code running at the Finally block:</p>
<pre name="code" class="csharp">try
{
	//Application logic goes here
}
catch
{
	throw;
}
finally
{
	//Your finally code goes here
}</pre>
<p><strong>What is the problem?</strong> The catch block in this case is completely unecessary.</p>
<p><strong>Why is it a problem?</strong> Not a big deal, but it represents unecessary lines of code that will make your code look dumb to your collegues.</p>
<p><strong>What to do?</strong> Just use a Try/Finally block:</p>
<pre name="code" class="csharp">try
{
	//Your application logic goes here
}
finally
{
	//Your finally code goes here
}</pre>
<p><strong>ps: methods used in the examples are using an anemic model for simplicity purposes. </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2009/07/21/basic-stuff-handling-exceptions-in-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>(Portuguese) Channel 9 Brasileiro</title>
		<link>http://blog.tucaz.net/en/2009/02/21/channel-9-brasileiro/</link>
		<comments>http://blog.tucaz.net/en/2009/02/21/channel-9-brasileiro/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 19:57:18 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[ArqCast]]></category>
		<category><![CDATA[Channel 9]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=248</guid>
		<description><![CDATA[Sorry, this entry is only available in Portuguese.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2009/02/21/channel-9-brasileiro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Portuguese) .NET Scrum &#8211; Projeto Open Source</title>
		<link>http://blog.tucaz.net/en/2008/12/28/net-scrum-projeto-open-source/</link>
		<comments>http://blog.tucaz.net/en/2008/12/28/net-scrum-projeto-open-source/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 20:16:31 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Scrum]]></category>
		<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Fluent Interfaces]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Spring.NET]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=195</guid>
		<description><![CDATA[Projeto .NET open source para gerenciamente de projetos utilizando Scrum como disciplina. Boas práticas de engenharia e conducação de projetos utilizando frameworks e práticas de mercado.]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/12/28/net-scrum-projeto-open-source/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>(Portuguese) Terceira reunião sobre arquitetura DotNetArchitects</title>
		<link>http://blog.tucaz.net/en/2008/12/11/terceira-reuniao-sobre-arquitetura-dotnetarchitects/</link>
		<comments>http://blog.tucaz.net/en/2008/12/11/terceira-reuniao-sobre-arquitetura-dotnetarchitects/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 22:57:43 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DotNetArchitects]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=180</guid>
		<description><![CDATA[Terceira reunião do grupo de discussão a respeito de arquitetura de software DotNetArchitects.]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/12/11/terceira-reuniao-sobre-arquitetura-dotnetarchitects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Portuguese) DotNetArchitects &#8211; Próximo Encontro</title>
		<link>http://blog.tucaz.net/en/2008/11/18/dotnetarchitects-proximo-encontro/</link>
		<comments>http://blog.tucaz.net/en/2008/11/18/dotnetarchitects-proximo-encontro/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 23:14:15 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[DotNetArchitects]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=143</guid>
		<description><![CDATA[Sorry, this entry is only available in Portuguese.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/11/18/dotnetarchitects-proximo-encontro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Portuguese) Primeira reunião do Grupo de Arquitetura</title>
		<link>http://blog.tucaz.net/en/2008/10/28/primeira-reuniao-do-grupo-de-arquitetura/</link>
		<comments>http://blog.tucaz.net/en/2008/10/28/primeira-reuniao-do-grupo-de-arquitetura/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 12:12:51 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Grupo de Estudos]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=123</guid>
		<description><![CDATA[Sorry, this entry is only available in Portuguese.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/10/28/primeira-reuniao-do-grupo-de-arquitetura/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Portuguese) Grupo de estudos sobre Arquitetura &#8211; 1ª Reunião</title>
		<link>http://blog.tucaz.net/en/2008/10/21/grupo-de-estudos-sobre-arquitetura/</link>
		<comments>http://blog.tucaz.net/en/2008/10/21/grupo-de-estudos-sobre-arquitetura/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 13:52:02 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[Grupo de Estudos]]></category>
		<category><![CDATA[Usergroup]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=110</guid>
		<description><![CDATA[Sorry, this entry is only available in Portuguese.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/10/21/grupo-de-estudos-sobre-arquitetura/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>(Portuguese) Novo Microsoft Architecture Guide lançado</title>
		<link>http://blog.tucaz.net/en/2008/09/24/novo-microsoft-architecture-guide-lancado/</link>
		<comments>http://blog.tucaz.net/en/2008/09/24/novo-microsoft-architecture-guide-lancado/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 13:49:12 +0000</pubDate>
		<dc:creator>tucaz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Arquitetura]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Architecture Guide]]></category>
		<category><![CDATA[Arquitetura de Referência]]></category>

		<guid isPermaLink="false">http://blog.tucaz.net/?p=87</guid>
		<description><![CDATA[Sorry, this entry is only available in Portuguese.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://blog.tucaz.net/category/desenvolvimento/arquitetura-desenvolvimento/feed/">Portuguese</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tucaz.net/en/2008/09/24/novo-microsoft-architecture-guide-lancado/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

