{ "rule": { "key": "squid:S1181", "repo": "squid", "name": "Throwable and Error classes should not be caught", "createdAt": "2013-08-09T14:40:54+0200", "severity": "BLOCKER", "status": "READY", "internalKey": "S1181", "isTemplate": false, "tags": [], "sysTags": [ "error-handling" ], "lang": "java", "langName": "Java", "htmlDesc": "

\nThrowable is the superclass of all errors and exceptions in Java.\nError is the superclass of all errors which are not meant to be caught by applications.\n

\n\n

\nCatching either Throwable or Error will also catch OutOfMemoryError or InternalError from which an application should not attempt to recover.\n

\n\n

Only Exception and its subclasses should be caught.

\n\n

Noncompliant Code Example

\n\n
\ntry { /* ... */ } catch (Throwable t) { /* ... */ }\ntry { /* ... */ } catch (Error e) { /* ... */ } \n
\n\n

Compliant Solution

\n\n
\ntry { /* ... */ } catch (Exception e) { /* ... */ }  \ntry { /* ... */ } catch (RuntimeException e) { /* ... */ }  \ntry { /* ... */ } catch (MyException e) { /* ... */ }  \n
", "defaultDebtChar": "RELIABILITY", "defaultDebtSubChar": "EXCEPTION_HANDLING", "debtChar": "RELIABILITY", "debtSubChar": "EXCEPTION_HANDLING", "debtCharName": "Reliability", "debtSubCharName": "Exception handling", "defaultDebtRemFnType": "CONSTANT_ISSUE", "defaultDebtRemFnOffset": "20min", "debtOverloaded": true, "debtRemFnType": "LINEAR", "debtRemFnCoeff": "20min", "params": [] }, "actives": [ { "qProfile": "java-default-with-mojo-conventions-49307", "inherit": "NONE", "severity": "BLOCKER", "params": [] } ] }