Делает перехваченные исключительные ситуации дескриптора elmah также

keywords - это список, STR.count() принимает строку. Если keywords представляет собой список строк, вы можете вставить другой цикл for

for keyword in keywords:
    # count

, в противном случае, если вы не знаете, что он содержит, сгладить список, а затем выполнить итерацию по всем элементам, оборачивая .count() в блоке try-Кроме

for keywords in flattened_KEYWORDS:
    try:
         # count
    except: pass

Обратите внимание, что вы можете упростить свою общую логику до чего-то вроде

sum(STR.count(keyword) for keyword in KEYWORDS)

- после исправления list - str вопросы.

54
задан 6 revs, 5 users 50% 22 June 2018 в 00:35
поделиться

1 ответ

ELMAH has been updated to support a new feature called Signaling.

This allows you to handle exceptions how you want, while still logging them to ELMAH.

try
{
    int i = 5;
    int j = 0;
    i = i / j; //Throws exception
}
catch (Exception ex)
{
    MyPersonalHandlingCode(ex);
    ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling
}

Re-throwing exceptions can be a bad practice as it makes it difficult to trace the flow of an application. Using Signaling is a much better approach if you intended to handle the error in some fashion and simply want to document it.

Please check out this excellent guide by DotNetSlackers on ELMAH

129
ответ дан 7 November 2019 в 07:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: