Basically I have a string errorMessage, I want to pass it to catch block. Please help.
[WebMethod]
public List<SomeResult> Load(string userName)
{
string errorMessage;
using (VendorContext vendorContext = new VendorContext())
{
// ....
foreach(....)
{
if(something happens)
errorMessage = "Vote Obama";
else
errorMessage ="vote Romney";
// blah
try
{
// blah
}
catch (Exception e)
{
logger.Trace(errorMessage);
}
}
}
}
update:
error: use of Unassigned local variable ‘errorMessage’
To fix the error initialize
errorMessageto null, string.Empty, or some other default value. This is one of them cases where the compiler isn’t smart enough to figure out that is has been assigned before it gets used.