I have a question, I tried to find some content in Google but I did not find it.
I have a block try catch
as follows:
try
{
//código
string idFormaPgto = Dictionaries.FormaPgto[_order.FK_PEDIDOS_FORMA_PAGAMENTO];
//restante do código
}
catch(Exception e)
{
}
The problem is that sometimes I will get a KeyNotFoundException
but the following code MUST continue and I need to set a default vallor for idFormaPgto
, I do not know if there is a more elegant and correct way of treating this, what I thought was:
try
{
//código
string idFormaPgto = "";
try
{
idFormaPgto = Dictionaries.FormaPgto[_order.FK_PEDIDOS_FORMA_PAGAMENTO];
}
catch(Exception e)
{
idFormaPgto = "1"; //tratamento do idFormaPgto
}
//restante do código
}
catch(Exception e)
{
}
My code solves the problem, but I believe that is not the most correct way to do this, perhaps by using some method of extending the class Dictionary
but I do not know any. The goal is to treat this KeyNotFoundException
without using try catch
within try catch