{"id":479913,"date":"2026-05-15T17:12:13","date_gmt":"2026-05-15T17:12:13","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=479913"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=479913","title":{"rendered":"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u0445 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u043e\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043d\u043e \u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043d\u0435 \u0443\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0436\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a \u0432 \u0431\u043b\u043e\u043a\u0435 <code>catch<\/code>? \u0422\u0430\u043c \u0432\u0435\u0434\u044c \u043a\u043e\u0434 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439! \u041d\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u044b\u0439 <code>LOG.warn(\"...\")<\/code> \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0418 \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u00ab\u043d\u0430\u0441\u043b\u043e\u0435\u043d\u0438\u0439\u00bb \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u0431\u043e\u044f. \u0412\u0441\u0451 \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u043e\u0434\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u044f\u0437\u044b\u043a\u0430 Java\u2026<\/p>\n<h3>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>catch<\/code>, \u00ab\u043f\u0440\u043e\u0433\u043b\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>try<\/code>.<\/p>\n<p><a class=\"anchor\" name=\"listing-1\" id=\"listing-1\"><\/a><\/p>\n<h4>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1<\/h4>\n<pre><code class=\"java\">public class Listing1 {    public static void main(String[] args) {        try {            System.out.println(\"&gt; TRY block\");            throw new RuntimeException(\"exception from TRY block\");        } catch (Exception e) {            System.out.println(\"&gt; CATCH block\");            System.out.println(\"&gt; \" + e);            throw new RuntimeException(\"exception from CATCH block\");        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u0434 \u0438\u0437 <a href=\"#listing-1\" rel=\"noopener noreferrer nofollow\">\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 1<\/a>. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 <code>try<\/code> \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u043e \u0432 \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0435\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0432\u043e\u0432\u0441\u0435:<\/p>\n<pre><code>&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread \"main\" java.lang.RuntimeException: exception from CATCH blockat Listing1.main(Listing1.java:9)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u041f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439, \u043d\u043e \u043d\u0435 \u0440\u0430\u0437\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439<\/h3>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u043b\u0435\u0447\u0451\u043c\u0441\u044f \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e <a href=\"https:\/\/dev.java\/learn\/exceptions\/catching-handling\/#try-with-resources\" rel=\"noopener noreferrer nofollow\">try-with-resources<\/a>. \u0421 \u043d\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0430\u044f. \u0415\u0441\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0438 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>try<\/code>, \u0438 \u0432 \u0431\u043b\u043e\u043a\u0435 <abbr class=\"habraabbr\" title=\"try-with-resources\" data-title=\"&lt;p&gt;try-with-resources&lt;\/p&gt;\" data-abbr=\"TWR\">TWR<\/abbr>, \u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0431\u0435\u0441\u0441\u043b\u0435\u0434\u043d\u043e, \u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c (<a href=\"https:\/\/dev.java\/learn\/exceptions\/catching-handling\/#suppressed\" rel=\"noopener noreferrer nofollow\">suppressed<\/a>) \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043d\u0435\u043c\u0443.<\/p>\n<p><a class=\"anchor\" name=\"listing-2\" id=\"listing-2\"><\/a><\/p>\n<h4>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2<\/h4>\n<pre><code class=\"java\">public class Listing2 {    public static void main(String[] args) throws Exception {        try (AutoCloseable r = () -&gt; {            System.out.println(\"&gt; TWR block\");            throw new RuntimeException(\"exception from TWR block\");        }) {            System.out.println(\"&gt; TRY block\");            throw new RuntimeException(\"exception from TRY block\");        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u0440\u043e\u0433\u043e\u043d\u0438\u043c <a href=\"#listing-2\" rel=\"noopener noreferrer nofollow\">\u043b\u0438\u0441\u0442\u0438\u043d\u0433 2<\/a> \u0438 \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u0431\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441\u0435:<\/p>\n<pre><code>&gt; TRY block&gt; TWR blockException in thread \"main\" java.lang.RuntimeException: exception from TRY blockat Listing2.main(Listing2.java:8)Suppressed: java.lang.RuntimeException: exception from TWR blockat Listing2.lambda$main$0(Listing2.java:5)at Listing2.main(Listing2.java:3)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0431\u043b\u043e\u043a\u0443 <code>catch<\/code>.<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, <abbr class=\"habraabbr\" title=\"try-with-resources\" data-title=\"&lt;p&gt;try-with-resources&lt;\/p&gt;\" data-abbr=\"TWR\">TWR<\/abbr> \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442, \u0438\u0431\u043e \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <strong>\u0434\u043e<\/strong> <code>catch<\/code>. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 <code>try<\/code> \u0438 \u044f\u0432\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c\u0443.<\/p>\n<p><a class=\"anchor\" name=\"listing-3\" id=\"listing-3\"><\/a><\/p>\n<h4>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3<\/h4>\n<pre><code class=\"java\">public class Listing3 {    public static void main(String[] args) {        try {            System.out.println(\"&gt; TRY block\");            throw new RuntimeException(\"exception from TRY block\");        } catch (RuntimeException primaryException) {            try {                System.out.println(\"&gt; CATCH block\");                System.out.println(\"&gt; \" + primaryException);                throw new RuntimeException(\"exception from CATCH block\");            } catch (RuntimeException secondaryException) {                primaryException.addSuppressed(secondaryException);                throw primaryException;            }        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c <a href=\"#listing-3\" rel=\"noopener noreferrer nofollow\">\u043b\u0438\u0441\u0442\u0438\u043d\u0433 3<\/a> \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 <code>catch<\/code> \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u043e:<\/p>\n<pre><code>&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread \"main\" java.lang.RuntimeException: exception from TRY blockat Listing3.main(Listing3.java:5)Suppressed: java.lang.RuntimeException: exception from CATCH blockat Listing3.main(Listing3.java:10)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/26\/docs\/api\/java.base\/java\/lang\/Throwable.html#addSuppressed(java.lang.Throwable)\" rel=\"noopener noreferrer nofollow\">Throwable.addSuppressed()<\/a> \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0435 \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>enableSuppression<\/code>, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0432 <code>true<\/code> (\u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0431\u044b\u043b\u043e \u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u0422\u0430\u043a, \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/26\/docs\/api\/java.base\/java\/lang\/Throwable.html#getSuppressed()\" rel=\"noopener noreferrer nofollow\">Throwable.getSuppressed()<\/a> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0435\u0449\u0451 \u043d\u0435\u0442 <strong>\u0438\u043b\u0438<\/strong> \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e. \u0420\u0430\u0437\u043b\u0438\u0447\u0438\u0442\u044c \u044d\u0442\u0438\u0445 \u0434\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u044f \u043d\u0435\u043b\u044c\u0437\u044f. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0435\u0440\u0435\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u0441\u043b\u0435\u2026 \u0410 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043c\u0443\u0447\u0430\u0442\u044c\u0441\u044f, \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u0446\u0435\u043f\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f.<\/p>\n<p><a class=\"anchor\" name=\"listing-4\" id=\"listing-4\"><\/a><\/p>\n<h4>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4<\/h4>\n<pre><code class=\"java\">public class Listing4 {    public static void main(String[] args) {        try {            System.out.println(\"&gt; TRY block\");            throw new RuntimeException(\"exception from TRY block\");        } catch (RuntimeException primaryException) {            try {                System.out.println(\"&gt; CATCH block\");                System.out.println(\"&gt; \" + primaryException);                throw new RuntimeException(\"exception from CATCH block\");            } catch (RuntimeException secondaryException) {                var joinedException = new RuntimeException(\"Joined exception\");                joinedException.addSuppressed(primaryException);                joinedException.addSuppressed(secondaryException);                throw joinedException;            }        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b <a href=\"#listing-4\" rel=\"noopener noreferrer nofollow\">\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 4<\/a> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e. \u041d\u043e \u0447\u0442\u043e-\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u0442\u0430\u043a: \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c. \u0422\u0430\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443:<\/p>\n<pre><code>&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread \"main\" java.lang.RuntimeException: Joined exceptionat Listing4.main(Listing4.java:12)Suppressed: java.lang.RuntimeException: exception from TRY blockat Listing4.main(Listing4.java:5)Suppressed: java.lang.RuntimeException: exception from CATCH blockat Listing4.main(Listing4.java:10)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u0441 \u0437\u0430\u043f\u0440\u0435\u0442\u043e\u043c \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 (\u043e\u043f\u044f\u0442\u044c-\u0442\u0430\u043a\u0438, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e), \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0430 \u044d\u0442\u043e \u0431\u044b\u043b\u0430 \u0432\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430.<\/p>\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e finally<\/h3>\n<p>\u041f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u043e\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>finally<\/code> \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0432\u0441\u0435\u0445 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u043b\u043e\u043a\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432 <code>finally<\/code> \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0430 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <abbr class=\"habraabbr\" title=\"try-with-resources\" data-title=\"&lt;p&gt;try-with-resources&lt;\/p&gt;\" data-abbr=\"TWR\">TWR<\/abbr>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 (\u0432\u0440\u043e\u0434\u0435 \u0444\u0430\u0439\u043b\u0430) \u043d\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d:<\/p>\n<p><a class=\"anchor\" name=\"listing-5\" id=\"listing-5\"><\/a><\/p>\n<h4>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 5<\/h4>\n<pre><code class=\"java\">public class Listing5 {    public static void main(String[] args) {        try (FinallyBlock f = new FinallyBlock()) {            System.out.println(\"&gt; Processing...\");            \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u0440\u0430\u0431\u043e\u0442\u0443         } finally {            \/\/ \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043f\u0443\u0441\u0442\u044b\u043c        }    }}class FinallyBlock implements AutoCloseable {    @Override    public void close() {        String message = \"&gt; Completed\";        System.out.println(message);        \/\/ \u0434\u0435\u043b\u0430\u0435\u043c c message \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451...    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0411\u043b\u043e\u043a <code>finally<\/code> \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 <abbr class=\"habraabbr\" title=\"try-with-resources\" data-title=\"&lt;p&gt;try-with-resources&lt;\/p&gt;\" data-abbr=\"TWR\">TWR<\/abbr> \u0432\u043e \u0432\u0441\u0451\u043c, \u043a\u0440\u043e\u043c\u0435:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 <code>catch<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435 <code>try<\/code>.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u2013 \u043d\u0435 \u0442\u0430\u043a\u0430\u044f \u0443\u0436 \u0431\u0435\u0437\u0443\u043c\u043d\u0430\u044f \u0437\u0430\u0442\u0435\u044f. \u041d\u043e \u0432\u0441\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432 \u043c\u0435\u0440\u0443. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u043e\u0434\u0438\u043d \u0443\u043c\u043d\u044b\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0439\u0442\u0435 \u043f\u0430\u0440\u0430\u043d\u043e\u0439\u044e \u0432 \u043c\u0430\u0440\u0430\u0437\u043c.<\/p>\n<p>\u0427\u0442\u043e \u0434\u043e \u044f\u0437\u044b\u043a\u0430 Java, \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0433\u043e \u0438\u0437\u044a\u044f\u043d\u0430\u043c\u0438. \u041e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c. \u0418 \u043b\u0443\u0447\u0448\u0435 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0447\u0435\u043c \u043d\u0435 \u0438\u043c\u0435\u0442\u044c.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1035762\/\">https:\/\/habr.com\/ru\/articles\/1035762\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u043e\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043d\u043e \u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043d\u0435 \u0443\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0436\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a \u0432 \u0431\u043b\u043e\u043a\u0435 catch? \u0422\u0430\u043c \u0432\u0435\u0434\u044c \u043a\u043e\u0434 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439! \u041d\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434.\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u044b\u0439 LOG.warn(&#171;&#8230;&#187;) \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0418 \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u00ab\u043d\u0430\u0441\u043b\u043e\u0435\u043d\u0438\u0439\u00bb \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u0431\u043e\u044f. \u0412\u0441\u0451 \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u043e\u0434\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u044f\u0437\u044b\u043a\u0430 Java\u2026\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 catch, \u00ab\u043f\u0440\u043e\u0433\u043b\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 try.\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1public class Listing1 {    public static void main(String[] args) {        try {            System.out.println(&#171;&gt; TRY block&#187;);            throw new RuntimeException(&#171;exception from TRY block&#187;);        } catch (Exception e) {            System.out.println(&#171;&gt; CATCH block&#187;);            System.out.println(&#171;&gt; &#187; + e);            throw new RuntimeException(&#171;exception from CATCH block&#187;);        }    }}\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u0434 \u0438\u0437 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 1. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 try \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u043e \u0432 \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0435\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0432\u043e\u0432\u0441\u0435:&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread &#171;main&#187; java.lang.RuntimeException: exception from CATCH blockat Listing1.main(Listing1.java:9)\u041f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439, \u043d\u043e \u043d\u0435 \u0440\u0430\u0437\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u043b\u0435\u0447\u0451\u043c\u0441\u044f \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e try-with-resources. \u0421 \u043d\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0430\u044f. \u0415\u0441\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0438 \u0432 \u0431\u043b\u043e\u043a\u0435 try, \u0438 \u0432 \u0431\u043b\u043e\u043a\u0435 TWR, \u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0431\u0435\u0441\u0441\u043b\u0435\u0434\u043d\u043e, \u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c (suppressed) \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043d\u0435\u043c\u0443.\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2public class Listing2 {    public static void main(String[] args) throws Exception {        try (AutoCloseable r = () -&gt; {            System.out.println(&#171;&gt; TWR block&#187;);            throw new RuntimeException(&#171;exception from TWR block&#187;);        }) {            System.out.println(&#171;&gt; TRY block&#187;);            throw new RuntimeException(&#171;exception from TRY block&#187;);        }    }}\u041f\u0440\u043e\u0433\u043e\u043d\u0438\u043c \u043b\u0438\u0441\u0442\u0438\u043d\u0433 2 \u0438 \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u0431\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441\u0435:&gt; TRY block&gt; TWR blockException in thread &#171;main&#187; java.lang.RuntimeException: exception from TRY blockat Listing2.main(Listing2.java:8)Suppressed: java.lang.RuntimeException: exception from TWR blockat Listing2.lambda$main$0(Listing2.java:5)at Listing2.main(Listing2.java:3)\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0431\u043b\u043e\u043a\u0443 catch.\u0420\u0435\u0448\u0435\u043d\u0438\u0435\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, TWR \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442, \u0438\u0431\u043e \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e catch. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 try \u0438 \u044f\u0432\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c\u0443.\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3public class Listing3 {    public static void main(String[] args) {        try {            System.out.println(&#171;&gt; TRY block&#187;);            throw new RuntimeException(&#171;exception from TRY block&#187;);        } catch (RuntimeException primaryException) {            try {                System.out.println(&#171;&gt; CATCH block&#187;);                System.out.println(&#171;&gt; &#187; + primaryException);                throw new RuntimeException(&#171;exception from CATCH block&#187;);            } catch (RuntimeException secondaryException) {                primaryException.addSuppressed(secondaryException);                throw primaryException;            }        }    }}\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043b\u0438\u0441\u0442\u0438\u043d\u0433 3 \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 catch \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u043e:&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread &#171;main&#187; java.lang.RuntimeException: exception from TRY blockat Listing3.main(Listing3.java:5)Suppressed: java.lang.RuntimeException: exception from CATCH blockat Listing3.main(Listing3.java:10)\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 Throwable.addSuppressed() \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0435 \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c enableSuppression, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0432 true (\u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).\u0410 \u0432\u043e\u0442 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0431\u044b\u043b\u043e \u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u0422\u0430\u043a, \u043c\u0435\u0442\u043e\u0434 Throwable.getSuppressed() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0435\u0449\u0451 \u043d\u0435\u0442 \u0438\u043b\u0438 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e. \u0420\u0430\u0437\u043b\u0438\u0447\u0438\u0442\u044c \u044d\u0442\u0438\u0445 \u0434\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u044f \u043d\u0435\u043b\u044c\u0437\u044f. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0435\u0440\u0435\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u0441\u043b\u0435\u2026 \u0410 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043c\u0443\u0447\u0430\u0442\u044c\u0441\u044f, \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u0446\u0435\u043f\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f.\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4public class Listing4 {    public static void main(String[] args) {        try {            System.out.println(&#171;&gt; TRY block&#187;);            throw new RuntimeException(&#171;exception from TRY block&#187;);        } catch (RuntimeException primaryException) {            try {                System.out.println(&#171;&gt; CATCH block&#187;);                System.out.println(&#171;&gt; &#187; + primaryException);                throw new RuntimeException(&#171;exception from CATCH block&#187;);            } catch (RuntimeException secondaryException) {                var joinedException = new RuntimeException(&#171;Joined exception&#187;);                joinedException.addSuppressed(primaryException);                joinedException.addSuppressed(secondaryException);                throw joinedException;            }        }    }}\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 4 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e. \u041d\u043e \u0447\u0442\u043e-\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u0442\u0430\u043a: \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c. \u0422\u0430\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443:&gt; TRY block&gt; CATCH block&gt; java.lang.RuntimeException: exception from TRY blockException in thread &#171;main&#187; java.lang.RuntimeException: Joined exceptionat Listing4.main(Listing4.java:12)Suppressed: java.lang.RuntimeException: exception from TRY blockat Listing4.main(Listing4.java:5)Suppressed: java.lang.RuntimeException: exception from CATCH blockat Listing4.main(Listing4.java:10)\u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u0441 \u0437\u0430\u043f\u0440\u0435\u0442\u043e\u043c \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 (\u043e\u043f\u044f\u0442\u044c-\u0442\u0430\u043a\u0438, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e), \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0430 \u044d\u0442\u043e \u0431\u044b\u043b\u0430 \u0432\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430.\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e finally\u041f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u043e\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 finally \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0432\u0441\u0435\u0445 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u043b\u043e\u043a\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432 finally \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0430 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c TWR, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 (\u0432\u0440\u043e\u0434\u0435 \u0444\u0430\u0439\u043b\u0430) \u043d\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d:\u041b\u0438\u0441\u0442\u0438\u043d\u0433 5public class Listing5 {    public static void main(String[] args) {        try (FinallyBlock f = new FinallyBlock()) {            System.out.println(&#171;&gt; Processing&#8230;&#187;);            \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u0440\u0430\u0431\u043e\u0442\u0443         } finally {            \/\/ \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043f\u0443\u0441\u0442\u044b\u043c        }    }}class FinallyBlock implements AutoCloseable {    @Override    public void close() {        String message = &#171;&gt; Completed&#187;;        System.out.println(message);        \/\/ \u0434\u0435\u043b\u0430\u0435\u043c c message \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451&#8230;    }}\u0411\u043b\u043e\u043a finally \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 TWR \u0432\u043e \u0432\u0441\u0451\u043c, \u043a\u0440\u043e\u043c\u0435:\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 catch.\u0412 \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435 try.\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u0420\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u2013 \u043d\u0435 \u0442\u0430\u043a\u0430\u044f \u0443\u0436 \u0431\u0435\u0437\u0443\u043c\u043d\u0430\u044f \u0437\u0430\u0442\u0435\u044f. \u041d\u043e \u0432\u0441\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432 \u043c\u0435\u0440\u0443. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u043e\u0434\u0438\u043d \u0443\u043c\u043d\u044b\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0439\u0442\u0435 \u043f\u0430\u0440\u0430\u043d\u043e\u0439\u044e \u0432 \u043c\u0430\u0440\u0430\u0437\u043c.\u0427\u0442\u043e \u0434\u043e \u044f\u0437\u044b\u043a\u0430 Java, \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0433\u043e \u0438\u0437\u044a\u044f\u043d\u0430\u043c\u0438. \u041e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c. \u0418 \u043b\u0443\u0447\u0448\u0435 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0447\u0435\u043c \u043d\u0435 \u0438\u043c\u0435\u0442\u044c.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1035762\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-479913","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/479913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=479913"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/479913\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=479913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=479913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=479913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}