{"id":77568,"date":"2020-04-03T10:18:20","date_gmt":"2020-04-03T04:48:20","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77568"},"modified":"2020-04-03T10:18:20","modified_gmt":"2020-04-03T04:48:20","slug":"java-exception","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-exception\/","title":{"rendered":"Java Exception &#8211; Learn with its Types, Methods &amp; Examples"},"content":{"rendered":"<p>When you create and develop programs, errors occur naturally. Sometimes, you misspell a variable name or a keyword, or sometimes there is a network connection problem, etc.<\/p>\n<p>These errors are very common and easy to handle errors and are known as Exception. To handle these exceptions, Java provides numerous ways to catch and prevent them.<\/p>\n<p>Exceptions are some unexpected situations that a programmer may face while programming. In this article, we will discuss an Exception in Java along with the cause of the exception, types of Java exceptions.<\/p>\n<p>We will also see what is an exception hierarchy in Java.<\/p>\n<h3>What is Java Exception?<\/h3>\n<p>Exception, in general, refers to some contradiction or unexpected situation, or in short, an unexpected error that occurs during program execution. There may be some cases during program development, where the programmer is not sure that this code-fragment is going to work correctly or not.<\/p>\n<p>The reason for this is that sometimes the resources are not available or sometimes the range of an array is invalid. These types of anomalous situations are called exceptions and the way to handle them is called exception handling.<\/p>\n<p>The unexpected errors or bugs during the runtime or normal execution of a program is a Java Exception.<\/p>\n<p>This exception causes disruption in the execution of the program.<\/p>\n<h4>Examples of Java Exception<\/h4>\n<p>Some common examples of Exceptions in Java are:<\/p>\n<ul>\n<li>Divide by zero errors<\/li>\n<li>Trying to access the array elements with an invalid index<\/li>\n<li>Invalid input data by the user<\/li>\n<li>Hard disk crash<\/li>\n<li>Opening a file that does not exist<\/li>\n<li>Heap memory exhausted<\/li>\n<li>Network connection loss in the middle of a communication<\/li>\n<li>JVM has run out of memory.<\/li>\n<\/ul>\n<h4>Causes of Exception in Java<\/h4>\n<p>An exception in Java occurs during the execution of a program. Exceptions are the unexpected events that occur during runtime and disrupts the normal flow of program execution.<\/p>\n<p>Some causes of exceptions can be:<\/p>\n<ul>\n<li>by user,<\/li>\n<li>by programmer,<\/li>\n<li>or by corrupted or failed physical resources.<\/li>\n<\/ul>\n<h3>Types of Exception in Java<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/types-of-java-exception.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77935\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/types-of-java-exception.jpg\" alt=\"\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<p>We have three categories of Exceptions in Java. These are Checked Exceptions, Unchecked Exceptions, and Errors. Let\u2019s discuss each of them in detail.<\/p>\n<h4>1. Checked Exceptions in java<\/h4>\n<p>A checked exception is a compile-time exception, that is, a Java compiler checks or notifies during the compilation-time. They occur during the compile-time.<\/p>\n<p>The compiler checks the checked exceptions during compilation to check whether the programmer has written the code to handle them or not. The programmer cannot simply ignore these exceptions and should take care to handle these exceptions.<\/p>\n<p>If the programmer does not write the code to handle them then there will be a compilation error. A method that throws a checked exception needs to either specify or handle it.<\/p>\n<p>A checked exception extends the Exception class. Some checked Exceptions are SQLException, IOException, ClassNotFoundException, InvocationTargetException, etc.<\/p>\n<p>For example, if we write a program to read data from a file using a FileReader class and if the file does not exist, then there is a FileNotFoundException.<\/p>\n<p><strong>Code to illustrate the concept of checked exception:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\nimport java.io.File;\nimport java.io.FileReader;\npublic class CheckedExceptions\n{\n  public static void main(String args[])\n  {\n    File file = new File(\"\/home\/techvidvan\/file.txt\");\n    FileReader fileReader = new FileReader(file);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.Error: Unresolved compilation problem:<br \/>\nUnhandled exception type FileNotFoundException<br \/>\nat project1\/com.techvidvan.exceptions.CheckedExceptions.main(CheckedExceptions.java:10)<\/div>\n<h5>SQLException<\/h5>\n<p>This type of exception occurs when a user attempts to execute invalid queries on a database and there are database access errors.<\/p>\n<h5>IOException<\/h5>\n<p>This type of exception occurs when a JVM fails to open an I\/O stream file.<\/p>\n<h5>ClassNotFoundException<\/h5>\n<p>This type of exception occurs when the JVM is unable to find the required class. It may occur when a class is removed from the CLASSPATH.<\/p>\n<h4>2. Unchecked Exceptions in Java<\/h4>\n<p>An exception that occurs during the execution of a program is called an unchecked or a runtime exception. Unlike the checked exceptions, the compiler generally ignores these exceptions during compilation rather, they are checked during the runtime.<\/p>\n<p>Therefore, the compiler does not check whether the programmer has written the code to handle them or not but it is the responsibility of the programmer to handle the unchecked exceptions and provide a safe exit.<\/p>\n<p>For example, if a program attempts to divide a number by zero. Or, when there is an illegal arithmetic operation, this impossible event generates a runtime exception.<\/p>\n<p>Suppose, we declare an array of size 10 in a program, and try to access the 12th element of the array, or with a negative index like -5, then we get an ArrayIndexOutOfBounds exception.<\/p>\n<p>Some unchecked exceptions are ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, NumberFormatException, InputMismatchException, IllegalStateException, etc. We will discuss each of them with an example.<\/p>\n<h5>ArrayIndexOutofBound<\/h5>\n<p>ArrayIndexOutOfBound Exception causes when a programmer tries to access an invalid index of the array (the array index that does not exist). That is, the programmer attempts to access an array with an invalid index.<\/p>\n<p>If the value of the array index is either beyond the array length or it is negative, then such error occurs.<\/p>\n<p><strong>Code to illustrate the concept of unchecked exception- ArrayIndexOutOfBounds Exception:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\npublic class UnCheckedExceptions\n{\n  public static void main(String args[])\n  {\n    \/\/ArrayIndexOutOfBoundsException\n    int array[] = {1, 2, 3, 4, 5};\n    System.out.println(array[7]);\n\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 5<br \/>\nat project1\/com.techvidvan.exceptions.UnCheckedExceptions.main(UnCheckedExceptions.java:8)<\/div>\n<h5>Arithmetic Exceptions<\/h5>\n<p>This type of exception occurs when a user tries to attempt an incorrect arithmetic operation in the program. For example, if you divide any number by zero, then there will be an ArithmeticException. Let us consider the following code snippet:<\/p>\n<p><strong>Code to illustrate the concept of unchecked exception- ArithmeticException:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\npublic class UnCheckedExceptions\n{\n  public static void main(String args[])\n  {\n    int number1 = 10;\n    int number2 = 0;\n    \/\/Arithmetic Exception\n    int result = number1\/number2;\n    System.out.println(\"Result of 10\/0 is: \" + result);\n\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.ArithmeticException: \/ by zero<br \/>\nat project1\/com.techvidvan.exceptions.UnCheckedExceptions.main(UnCheckedExceptions.java:10)<\/div>\n<p><em><strong>Note:<\/strong> In case of unchecked exceptions, the compiler will never force you to declare them in the method using <strong>throws<\/strong> keyword or to use a <strong>try-catch<\/strong> block to handle them.<\/em><\/p>\n<h5>NullPointerException in Java<\/h5>\n<p>This type of exception occurs when the JVM attempts to perform an operation on an object that points to no data, or null. For example, consider the following code snippet:<\/p>\n<p><strong>Code to illustrate the concept of unchecked exception- NullPointerException:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\npublic class UnCheckedExceptions\n{\n  public static void main(String args[])\n  {\n    \/\/NullPointerException\n    String myString = null; \/\/ null value\n    System.out.println(myString.charAt(0));\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.NullPointerException<br \/>\nat project1\/com.techvidvan.exceptions.UnCheckedExceptions.main(UnCheckedExceptions.java:8)<\/div>\n<h5>NumberFormatException in Java<\/h5>\n<p>This type of exception occurs when a program attempts to convert a string to a numeric datatype. For example, consider the following code snippet:<\/p>\n<p><strong>Code to illustrate the concept of unchecked exception- NumberFormatException<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\npublic class UnCheckedExceptions\n{\n  public static void main(String args[])\n  {\n    \/\/ \"Number\" is not a integer, it is string\n    \/\/NumberFormatException\n    int number = Integer.parseInt (\"Number\") ;\n    System.out.println(number);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.NumberFormatException: For input string: &#8220;Number&#8221;<br \/>\nat java.base\/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)<br \/>\nat java.base\/java.lang.Integer.parseInt(Integer.java:658)<br \/>\nat java.base\/java.lang.Integer.parseInt(Integer.java:776)<br \/>\nat project1\/com.techvidvan.exceptions.UnCheckedExceptions.main(UnCheckedExceptions.java:8)<\/div>\n<h5>IllegalArgumentException in Java<\/h5>\n<p>When we pass an inappropriate or incorrect argument to a method, then this type of exception occurs. For example, if we define a method that accepts only non-empty string parameters.<\/p>\n<p>But, the user provides a null string as an input. In such cases, we will get an IllegalArgumentException to indicate that you cannot pass a null input string to the method.<\/p>\n<h5>IllegalStateException in Java<\/h5>\n<p>When the state of the environment does not match the input operation, then the IllegalStateException occurs.<\/p>\n<h4>3. Errors in java<\/h4>\n<p>An Error is not an exception but we consider it as a type of exception. An error is a severe problem or situation that is impossible for a user or a developer to recover.<\/p>\n<p>The cause of Errors in Java is when a user overlooks a code or rarely takes care of a mistake. For instance, if a queue is full and overflow occurs, a blunder will emerge.<\/p>\n<p>Some Errors in Java are VirtualMachineError, OutOfMemoryError, AssertionError, etc.<\/p>\n<p>Consider a situation, when a program attempts to allocate memory from the JVM but there is not enough space to satisfy the user request. Or, when a program tries to load a class file by calling Class.forName() method and the class file is corrupt. Such exceptions are known as an error.<\/p>\n<h5>Error vs Exception<\/h5>\n<p><strong>Error<\/strong><\/p>\n<p>An Error indicates a non-recoverable condition and therefore we should not write the code to catch it. Errors usually cause the JVM to display a message and exit.<\/p>\n<p><strong>Exception<\/strong><\/p>\n<p>Exception is a recoverable condition that a program might try to handle.<\/p>\n<h4>Exception Hierarchy in Java<\/h4>\n<p>Below is a diagram of the exception hierarchy in Java. The <strong>Throwable<\/strong> class is the parent class of all <strong>Errors<\/strong> and <strong>Exceptions<\/strong> <strong>classes.<\/strong> The Error object describes internal errors that are non-resolvable for example resource exhaustion, etc.<\/p>\n<p>An Exception object describes a recoverable error that a programmer should handle properly.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-exception-hierarchy.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77936\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-exception-hierarchy.jpg\" alt=\"\" width=\"590\" height=\"606\" \/><\/a><\/p>\n<p>Let\u2019s talk about this class hierarchy:<\/p>\n<h5>Throwable class<\/h5>\n<p>It is the root class of all exception classes. Its immediate subclasses are:<\/p>\n<ul>\n<li>Error class<\/li>\n<li>Exception class<\/li>\n<\/ul>\n<h5>Exception class<\/h5>\n<p>This class handles conditions that user programs can reasonably deal with. The exceptions are usually the result of some flaws in the program.<\/p>\n<p>Some examples of Exceptions are:<\/p>\n<ul>\n<li>Division by zero error<\/li>\n<li>Array out-of-bounds error<\/li>\n<\/ul>\n<h5>Error class<\/h5>\n<p>Error class is an abnormal condition and a program should not try to catch or handle it on its own.<\/p>\n<p>Some examples of Errors are:<\/p>\n<ul>\n<li>Out of memory errors<\/li>\n<li>Hard Disk crash<\/li>\n<\/ul>\n<h4>How does the JVM handle an exception- Default Exception Handler in Java<\/h4>\n<p>Whenever an exception occurs within a method, some activities take place internally. The following points summarize these activities:<\/p>\n<ul>\n<li>When an exception occurs inside a method, the method gives the object of exception to the JVM to handle it. We call this process of creating an exception object and handing it to the runtime system as throwing an exception. The created object contains information about the error, including its type and the state of the program during the occurrence of the error.<\/li>\n<li>Then, the JVM searches the method call stack that contains the method that contains a code to handle the exception.<\/li>\n<li>When the system finds an appropriate handler, it passes the exception to the handler.<\/li>\n<li>If the runtime system finds no appropriate exception handler, then both the runtime system and the program terminates and uses the default exception handler.<\/li>\n<\/ul>\n<h4>Java Exception Methods<\/h4>\n<p>Following is the list of important methods available in the Throwable class.<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td><b>S.N.<\/b><\/td>\n<td><b>Method\u00a0<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><span style=\"font-weight: 400\">public String getMessage()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns a detailed description of the occurred exception.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><span style=\"font-weight: 400\">public Throwable getCause()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the cause of the occurred exception\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><span style=\"font-weight: 400\">public String toString()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the result of the getMessage() method concatenated with the name of the class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><span style=\"font-weight: 400\">public void printStackTrace()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method prints the result of the toString() method along with the stack trace to the error output stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>5<\/b><\/td>\n<td><span style=\"font-weight: 400\">public StackTraceElement [] getStackTrace()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns an array containing each element of the stack trace.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>User-defined or customized Exception in Java<\/h4>\n<p>We know that Java comes with a rich set of in-built exception classes, but, there are some situations in which we may encounter various application-specific errors. We need to define our own exceptions to handle such errors or exceptions.<\/p>\n<p>Therefore, we can create customized exceptions to serve this purpose.<\/p>\n<h4>Rules for Java Exception<\/h4>\n<p>While defining a user-defined exception, we need to take care of the following aspects:<\/p>\n<ul>\n<li>The user-defined exception class should extend the Exception class.<\/li>\n<li>In the user-defined exception class, the programmer should override the toString() method.<\/li>\n<\/ul>\n<p><strong>Code to create and use a user-defined exception:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.exceptions;\npublic class NegativeAgeException extends Exception\n{\n  private static int age;\n  public NegativeAgeException(int age)\n  {\n    this.age=age;\n  }\n  public String toString()\n  {\n    return \"Age can't be negative\";\n  }\n  public static void main(String args[]) throws Exception\n  {\n    NegativeAgeException obj = new NegativeAgeException( -10 );\n    if(age &lt; 0)\n    {\n      throw new NegativeAgeException(age);\n    }\n    else\n    {\n      System.out.println(\"Entered age is: \" +age);\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; Age can&#8217;t be negative<br \/>\nat project1\/com.techvidvan.exceptions.NegativeAgeException.main(NegativeAgeException.java:20)<\/div>\n<h3>Summary<\/h3>\n<p>There are three types of exceptions in Java that we studied today in this article. They are checked, unchecked, and error. We can handle every exception in our own way. We also covered some important subtypes of checked and unchecked exceptions with examples.<\/p>\n<p>Coming to the end of this article, you would have become an expert in creating your own custom exceptions.<\/p>\n<p>Thank you for reading this article. Do share it on Social Media.<\/p>\n<p>Keep Learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you create and develop programs, errors occur naturally. Sometimes, you misspell a variable name or a keyword, or sometimes there is a network connection problem, etc. These errors are very common and easy&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77935,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2205,2206,2207,2208,2209,2210,2211,2094,2212,2213],"class_list":["post-77568","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-benefits-of-java-exception","tag-checked-exceptions-in-java","tag-exception-in-java","tag-how-jvm-handles-an-exception-in-java","tag-java-exception","tag-java-exception-hierarchy","tag-java-exception-methods","tag-nullpointerexceptions","tag-types-of-java-exception","tag-unchecked-exception-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Exception - Learn with its Types, Methods &amp; Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Java Exception - With thisarticle learn about Java Exception in detail along with its types, rules, methods &amp; Class &amp; also explore Java Exception Hierarchy .\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-exception\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Exception - Learn with its Types, Methods &amp; Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Java Exception - With thisarticle learn about Java Exception in detail along with its types, rules, methods &amp; Class &amp; also explore Java Exception Hierarchy .\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-exception\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-03T04:48:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Exception - Learn with its Types, Methods &amp; Examples - TechVidvan","description":"Java Exception - With thisarticle learn about Java Exception in detail along with its types, rules, methods & Class & also explore Java Exception Hierarchy .","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-exception\/","og_locale":"en_US","og_type":"article","og_title":"Java Exception - Learn with its Types, Methods &amp; Examples - TechVidvan","og_description":"Java Exception - With thisarticle learn about Java Exception in detail along with its types, rules, methods & Class & also explore Java Exception Hierarchy .","og_url":"https:\/\/techvidvan.com\/tutorials\/java-exception\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-04-03T04:48:20+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Exception &#8211; Learn with its Types, Methods &amp; Examples","datePublished":"2020-04-03T04:48:20+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/"},"wordCount":1954,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg","keywords":["Benefits of Java Exception","Checked exceptions in java","Exception in Java","How JVM handles an Exception in Java","Java Exception","Java Exception\u00a0Hierarchy","Java Exception Methods","nullpointerexceptions","Types of Java Exception","Unchecked Exception in Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-exception\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/","url":"https:\/\/techvidvan.com\/tutorials\/java-exception\/","name":"Java Exception - Learn with its Types, Methods &amp; Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg","datePublished":"2020-04-03T04:48:20+00:00","description":"Java Exception - With thisarticle learn about Java Exception in detail along with its types, rules, methods & Class & also explore Java Exception Hierarchy .","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-exception\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/types-of-java-exception.jpg","width":802,"height":420,"caption":"java exception"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-exception\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Exception &#8211; Learn with its Types, Methods &amp; Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77568"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77568\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77935"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}