-
Notifications
You must be signed in to change notification settings - Fork 0
/
component---src-pages-content-articles-backup-java-chained-exceptions-in-java-index-md-65f20df4fe577214dcf1.js
2 lines (2 loc) · 47 KB
/
component---src-pages-content-articles-backup-java-chained-exceptions-in-java-index-md-65f20df4fe577214dcf1.js
1
2
(window.webpackJsonp=window.webpackJsonp||[]).push([[17],{D6Id:function(e,a,n){"use strict";n.r(a),n.d(a,"_frontmatter",(function(){return s})),n.d(a,"default",(function(){return m}));n("rGqo"),n("yt8O"),n("Btvt"),n("RW0V"),n("91GP"),n("q1tI");var t=n("7ljp");var s={templateKey:"article",published:!1,displayComments:!0,showAuthorInfo:!1,author:"narramadan",title:"Chained Exceptions in Java",description:"In this article, we’ll have a very brief look at what Exception is and go in depth about discussing the chained exceptions in Java",date:"2019-12-17T23:46:37.121Z",updated:"2019-12-17T23:46:37.121Z",cover:"../../../images/blog-banners/Java-banner-1200x690.png",category:"testing",tags:["java","exceptions","featured"]},c={_frontmatter:s};function m(e){var a=e.components,n=function(e,a){if(null==e)return{};var n,t,s={},c=Object.keys(e);for(t=0;t<c.length;t++)n=c[t],a.indexOf(n)>=0||(s[n]=e[n]);return s}(e,["components"]);return Object(t.mdx)("wrapper",Object.assign({},c,n,{components:a,mdxType:"MDXLayout"}),Object(t.mdx)("h2",null,"Intro"),Object(t.mdx)("p",null,"In this article, we’ll have a very brief look at what Exception is and go in depth about discussing the chained exceptions in Java."),Object(t.mdx)("p",null,"Simply put, an exception is an event that disturbs the normal flow of the program’s execution. Let’s now see exactly how we can chain exceptions to get better semantics out of them."),Object(t.mdx)("h2",null,"Chained Exceptions"),Object(t.mdx)("p",null,"Chained Exception helps to identify a situation in which one exception causes another Exception in an application."),Object(t.mdx)("p",null,Object(t.mdx)("strong",{parentName:"p"},"For instance, consider a method which throws an ArithmeticException")," because of an attempt to divide by zero but the actual cause of exception was an I/O error which caused the divisor to be zero.The method will throw the ArithmeticException to the caller. The caller would not know about the actual cause of an Exception. Chained Exception is used in such situations."),Object(t.mdx)("p",null,"This concept was introduced in JDK 1.4."),Object(t.mdx)("p",null,"Let’s see how chained exceptions are supported in Java."),Object(t.mdx)("h2",null,"Throwable Class"),Object(t.mdx)("p",null,"Throwable class has some constructors and methods to support chained exceptions. Firstly, let’s look at the constructors."),Object(t.mdx)("ul",null,Object(t.mdx)("li",{parentName:"ul"},Object(t.mdx)("code",Object.assign({parentName:"li"},{className:"language-text"}),"Throwable(Throwable cause)")," – Throwable has a single parameter, which specifies the actual cause of an Exception."),Object(t.mdx)("li",{parentName:"ul"},Object(t.mdx)("code",Object.assign({parentName:"li"},{className:"language-text"}),"Throwable(String desc, Throwable cause)")," – this constructor accepts an Exception description with the actual cause of an Exception as well.")),Object(t.mdx)("p",null,"Next, let’s have a look at the methods this class provides:"),Object(t.mdx)("ul",null,Object(t.mdx)("li",{parentName:"ul"},Object(t.mdx)("code",Object.assign({parentName:"li"},{className:"language-text"}),"getCause()")," method – This method returns the actual cause associated with current Exception."),Object(t.mdx)("li",{parentName:"ul"},Object(t.mdx)("code",Object.assign({parentName:"li"},{className:"language-text"}),"initCause()")," method – It sets an underlying cause with invoking Exception")),Object(t.mdx)("h1",null,"Example"),Object(t.mdx)("p",null,"Now, let’s look at the example where we will set our own Exception description and throw a chained Exception:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MyChainedException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"["),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"]")," args",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"try")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throw")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"ArithmeticException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Top Level Exception."'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"initCause"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"IOException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"IO cause."'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"catch"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"ArithmeticException")," ae",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"System"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"out",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"println"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Caught : "')," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"+")," ae",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"System"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"out",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"println"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Actual cause: "'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"+")," ae",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getCause"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")," \n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(t.mdx)("p",null,"As guessed, this will lead to:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Caught"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"lang",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"ArithmeticException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Top")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Level")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Actual")," cause",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"io",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"IOException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," IO cause",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),".")))),Object(t.mdx)("h2",null,"Why Chained Exceptions?"),Object(t.mdx)("p",null,"We need to chain the exceptions to make logs readable. Let’s write two examples. First without chaining the exceptions and second, with chained exceptions. Later, we will compare how logs behave in both of the cases."),Object(t.mdx)("p",null,"To start, we will create a series of Exceptions:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"extends")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," message",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Throwable")," cause",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"super"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"message",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," cause",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," message",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"super"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"message",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"extends")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token comment"}),"// Both Constructors"),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(t.mdx)("p",null,"Now, let’s start using the above exceptions in code examples."),Object(t.mdx)("h3",null,"Without Chaining"),Object(t.mdx)("p",null,"Let’s write an example program without chaining our custom exceptions."),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"["),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"]")," args",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"try")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"catch")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException")," e",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n e",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"printStackTrace"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throw")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Leave not sanctioned."'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throw")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Team Lead Upset"'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(t.mdx)("p",null,"In the example above, logs will look like this:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),"com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Team")," lead ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Upset"),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"46"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"34"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"29"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," in thread ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"main"')," com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Leave")," not sanctioned",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"37"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"29"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")))),Object(t.mdx)("h3",null,"With Chaining"),Object(t.mdx)("p",null,"Next, let’s write an example with chaining our custom exceptions:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"["),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"]")," args",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"try")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"catch")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException")," e",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throw")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Leave not sanctioned."'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," e",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throws")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"throw")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Team lead Upset."'),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(t.mdx)("p",null,"Finally, let’s look at the logs obtained with chained exceptions:"),Object(t.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(t.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(t.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Exception")," in thread ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"main"')," com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"NoLeaveGrantedException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Leave")," not sanctioned",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),".")," \n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"36"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," \n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"main"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"29"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," \n",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Caused")," by",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TeamLeadUpsetException"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Team")," lead ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Upset"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"\n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"howIsTeamLead"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"44"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," \n at com",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"baeldung",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"chainedexception",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"exceptions",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),"\n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getLeave"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"MainClass"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"java",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"34"),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," \n ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),".")," ",Object(t.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"1")," more"))),Object(t.mdx)("p",null,"We can easily compare shown logs and conclude that the chained exceptions lead to cleaner logs."),Object(t.mdx)("h2",null,"Conclusion"),Object(t.mdx)("p",null,"In this article, we had a look at chained exceptions concept."),Object(t.mdx)("p",null,"The implementation of all examples can be found in the Github project – this is a Maven-based project, so it should be easy to import and run as it is."))}m.isMDXComponent=!0}}]);
//# sourceMappingURL=component---src-pages-content-articles-backup-java-chained-exceptions-in-java-index-md-65f20df4fe577214dcf1.js.map