I saw here numerous people talking of ways to catch exception from async fonctions, yet nothing worked from me.
I used some code to make an IRC bot : https://github.com/BenFradet/RiotSharp
(since the exception is inherited from WebException
it should do the same if you want to test)
So i tried async functions. When the user is not found by a function from RiotApi, GetSummoner()
for example, a 404 is thrown as RiotSharpException
.
try
{
RiotSharp.SummonerEndpoint.Summoner summoner = api.GetSummoner(region,name);
SendSummonersDetails(summoner, e.Message.MessageTarget);
}
catch (RiotSharpException ex)
{
string error = string.Format(this.RegionNotFound, command[2]);
irc.Send(new IRCMessage("PRIVMSG", e.Message.MessageTarget, error));
}
I have used that numerous time and i can catch that 404. Yet if i use the async version : wether i go for
try
{
RiotSharp.SummonerEndpoint.Summoner summoner = await api.GetSummonerAsync(region,name);
SendSummonersDetails(summoner, e.Message.MessageTarget);
}
catch (RiotSharpException ex)
{
string error = string.Format(this.RegionNotFound, command[2]);
irc.Send(new IRCMessage("PRIVMSG", e.Message.MessageTarget, error));
}
or for Task and then away, the try/catch won't catch the exception.
I tried everything i saw here : Catch an exception thrown by an async void method
I tried too the ContinueWith TaskContinuationOptions.OnlyOnFaulted
which did not work either.
I use VS 2013 and framework 4.5ish
I am fairly lost atm and used all i found here and nothing worked, maybe someone can think of something ?!