Hello, is there an ETA for exception filter support for IL2CPP. I’ve started writing a fair bit of async/await code and am running into some places where exception filtering would be nice to have.
There is also nothing suggesting that the feature is broken… I thought it was supported and working this whole time! (it compiles and runs fine in the editor), but then I just happened upon this in the documenation:
And, uhh, yeah, this was news to me as we are using some exception filtering in one of our production apps. There is no hint or anything that this feature doesn’t work.
Anyway, just wondering if this will be supported at some point, and if not is it possible to detect it and have the editor tell us that it wont work?
We don’t have an ETA for full exception filter support. At the moment many exception filters will work, but there are some complex exception filter cases which don’t work.
The bad news around exception filters is that we don’t have good documentation or diagnostics to allow you to know the difference (as you have likely discovered).
So far, the need for exception filters has been low enough that adding complete support has not been a priority.
Are you willing or able to share the use case you have? I’d love to better understand how they work and don’t work in your cases.
A common use case of Exception filters is when you want to handle Task cancellation:
public async Task<int> BarAsync()
{
try
{
var x = await FooAsync();
return x * 2;
}
catch (Exception ex) when (!(ex is OperationCanceledException)) // when (ex is not OperationCanceledException) at C# 9.0
{
return -1;
}
}
Yes, this use of except filters should work. Although, couldn’t you accomplish the same behavior without exception filters?
public async Task<int> BarAsync()
{
try
{
var x = await FooAsync();
return x * 2;
}
catch (Exception ex)
{
if (!(ex is OperationCanceledException))
return -1;
throw;
}
}
Hey sorry I forgot to get back around to this. Is there a list of scenarios where it wont work? What determines whether it would work or not? Why would the example above work?
Unfortunately no, we don’t have a clear list of what will and won’t work. This is the biggest part of the problem, as it makes the use of exception filters difficult. That is why we don’t recommend their use.
Some very simple cases, with just a single catch statement with an exception filter will work. More complex ones that involved multiple catch statements usually don’t work.
The example I provided above does not use exception filters.