A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Two Functions behaves differently
Vuyiswa Maseko
351
Reputation points
Good Day
i have two functions which are the same but behave differently
public async static Task<TOKEN_MODEL> Retrieve_Token()
{
TOKEN_MODEL token = null ;
try
{
try
{
token = await BlobCache.LocalMachine.GetObject<TOKEN_MODEL>("TOKEN1");
}
catch (KeyNotFoundException)
{
}
}
catch (Exception ex)
{
if (ex.Message == "Sequence contains no elements.")
{
return null;
}
else
{
return null;
}
}
return token;
}
And the second Function is
public async static Task<USERS_Model> RetrieveUserInfo()
{
USERS_Model Userinfo = null;
try
{
try
{
Userinfo =await BlobCache.LocalMachine.GetObject<USERS_Model>("USERDAT");
}
catch (KeyNotFoundException)
{
}
}
catch (KeyNotFoundException ex)
{
if (ex.Message == "Sequence contains no elements.")
{
return null;
}
else
{
return null;
}
}
return Userinfo;
}
and i am calling these two function in App.cs like this
TOKEN_MODEL token_model = await GenericMethods.Retrieve_Token();
and if there is no value , it will return Null and assign the object "token_model " with null which is ok
and the second one which is a problem
USERS_Model userinfo= await GenericMethods.RetrieveUserInfo();
The above line directly jumps to my exception handling code section instead of also assigning the object "userinfo" with null with an exception
System.InvalidOperationException: Sequence contains no elements.
Thanks
Developer technologies | .NET | Xamarin
Developer technologies | .NET | Xamarin
Sign in to answer