C
C#2y ago
Halfbax

❔ Custom "block" statement such as while..do

Hello, is it possible to build a custom block? For example
// usage
DoRequestAsync
{
Categories = await _stockBrowser.GetCategoriesAsync();
}

// code behind DoRequest
private async Task DoRequestAsync()
{
try
{
// children
}
catch (Exception e)
{
Console.WriteLine(e);
Error = true;
}
}
// usage
DoRequestAsync
{
Categories = await _stockBrowser.GetCategoriesAsync();
}

// code behind DoRequest
private async Task DoRequestAsync()
{
try
{
// children
}
catch (Exception e)
{
Console.WriteLine(e);
Error = true;
}
}
9 Replies
Halfbax
HalfbaxOP2y ago
I have a lot of requests that requires a try catch block.
Aaron
Aaron2y ago
no, C# doesn't have a way to add new syntax
Halfbax
HalfbaxOP2y ago
What would be the best way to solve the try catch disaster? Use a try catch around each request?
Aaron
Aaron2y ago
that highly depends on how the rest of your code is structured
Thinker
Thinker2y ago
I mean you could sorta emulate it
await DoRequestAsync(async () =>
{
Categories = await _stockBrowser.GetCategoriesAsync();
}):
await DoRequestAsync(async () =>
{
Categories = await _stockBrowser.GetCategoriesAsync();
}):
Angius
Angius2y ago
The usual way of handling that is to have a global exception handler and let the exceptions bubble up
cptcrawler
cptcrawler2y ago
you can always use ANTLR 😆
demidev_mb
demidev_mb2y ago
Use Polly, it's ultimate library for this kind of things.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server