I have a method in c#, in which it return an object! I need to use a try catch here
this is my method
public T FromBinary()
{
T obj;
try
{
using (Stream stream = File.Open(this.serializeFilePath, FileMode.Open))
{
var binaryFormatter = new BinaryFormatter();
obj=(T)binaryFormatter.Deserialize(stream);
}
}
catch (Exception e)
{
EventLog.WriteEntry("Cannot convert Binary to object", e.Message + "Trace" + e.StackTrace);
}
return obj;
}
But i am getting an error
Use of unassigned local variable 'obj'.
How can I use try catch in method having return object T?