Home
Register
About
Login
Categories
C#
(13)
VB.NET
(0)
F#
(0)
ASP.NET
(15)
JavaScript
(4)
C++
(0)
C
(0)
Python
(0)
Ruby
(0)
Rails
(0)
J#
(0)
SQL
(0)
VB Script
(0)
HTML
(0)
CSS
(2)
XML
(2)
XSLT
(0)
Unit Testing
(7)
Architecture
(2)
Ajax
(0)
Project Management
(0)
LINQ to SQL
(2)
LINQ
(0)
LINQ to XML
(1)
NHibernate
(0)
Active Record
(0)
Silverlight
(0)
ASP.NET MVC
(0)
Life
(0)
Book Reviews
(0)
WPF
(1)
Visual Studio
(0)
Logging Exceptions!
by Krammer on 5/8/2008 11:42:30 AM
I have the following flow for logging exceptions. How can I improve on this?
private bool AddCustomer(Customer customer)
{
bool result = false;
try
{
// code to add the customer
result = true;
}
catch (Exception ex)
{
// logg the exception
Logger.Log(ex);
}
return result;
}
Refactor it!
Your code looks clean enough! But you can make is little better by introducing extension methods. This will make the code more readable.
by azamsharp on 5/8/2008 12:48:31 PM
public static class ExtensionMethods
{
public static void Log(this Exception ex)
{
LogManager.Log(ex);
}
}
private bool AddCustomer(Customer customer)
{
bool result = false;
try
{
// code to add the customer
result = true;
}
catch (Exception ex)
{
ex.Log(); // much nicer!
}
return result;
}
Please log in to refactor the code!
Login