Bad exception category (BadExceptionCategory)¶
| Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
|---|---|---|---|---|---|
Code smell |
BSL |
Info |
Yes |
5 |
badpractice |
Description¶
It is forbidden to use abstract, generic, or system error categories when throwing exceptions using the functional form of Raise (or ВызватьИсключение).
Specifying general categories such as AllErrors, OtherError, or base language execution/compilation error categories obscures the true semantic meaning of the exception. This prevents the calling code from properly classifying the issue, routing it to specialized logging channels, or performing targeted handling (e.g., retrying an operation on temporary network glitches).
Instead of generic groups, specific application-level error categories should always be preferred (e.g., ErrorCategory.ConfigurationError, ErrorCategory.InvalidParameterValue, etc.).
The diagnostic rule checks the second argument of the statement and reports an issue if any of the following forbidden categories are used:
* AllErrors / ВсеОшибки
* OtherError / ПрочаяОшибка
* ScriptCompilationError / ОшибкаКомпиляцииВстроенногоЯзыка
* ScriptRuntimeError / ОшибкаВоВремяВыполненияВстроенногоЯзыка
* ScriptRaisedException / ИсключениеВызванноеИзВстроенногоЯзыка
Examples¶
Incorrect
// Using a category that is too broad or abstract
Raise("Failed to connect to the service", ErrorCategory.AllErrors);
ВызватьИсключение("Invalid data format", КатегорияОшибки.ПрочаяОшибка);
// Specifying a distinct application-level error category
Raise("Failed to connect to the service", ErrorCategory.NetworkError);
ВызватьИсключение("Invalid data format", КатегорияОшибки.ОшибкаКонфигурации);
Sources¶
Source: 1С:Предприятие 8.3.21. Документация. Глава 4. Встроенный язык. 4.6.10.2. Вызвать исключение
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:BadExceptionCategory-off
// BSLLS:BadExceptionCategory-on
Parameter for config¶
"BadExceptionCategory": false