{"id":13524,"date":"2020-03-18T18:03:46","date_gmt":"2020-03-19T01:03:46","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=13524"},"modified":"2023-12-01T02:33:35","modified_gmt":"2023-12-01T10:33:35","slug":"java-while-loop","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/java-while-loop\/","title":{"rendered":"Exception Handling with Try Catch in Java"},"content":{"rendered":"\n<p>Even the best programmers make mistakes in their code. An error could occur because of a typo, an unexpected user input, or for many other reasons which are difficult to track.<br><\/p>\n\n\n\n<p>That\u2019s where exception handling comes in. Good code includes exception handlers, which will respond to an error in code in a predefined way. Exception handlers are useful because they instruct a program on how to respond if and when an error occurs.<br><\/p>\n\n\n\n<p>In Java, the <code>try...catch<\/code> block is used for exception handling. This tutorial will discuss the basics of exception handling, how to use the <code>try...catch<\/code> block to handle exceptions, and how to use the <code>finally<\/code> statement with <code>try...catch<\/code>. We\u2019ll also walk through a few examples of the <code>try...catch<\/code> block in action.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Exceptions<\/h2>\n\n\n\n<p>Exceptions are unexpected events that occur when a program is being executed. An exception will disrupt the flow of a program and can cause a program to stop running before it has completed.<br><\/p>\n\n\n\n<p>Exceptions occur for a wide variety of reasons, which include: being unable to access a server, code errors, typos, opening non-existent files, erroneous user input, and more.<br><\/p>\n\n\n\n<p>Error messages are unlike exceptions in Java. Errors refer to conditions being met from which a program cannot recover, such as running out of memory. So, errors are not usually handled by developers.<br><\/p>\n\n\n\n<p>But exceptions are problems within a program that can be handled. When an exception is raised, an object is created called an <strong>exception object<\/strong>. These objects contain data on the exception, such as its name and where it was raised in the program.<br><\/p>\n\n\n\n<p>Now you know the basics of exception handling in Java, we can start using the <code>try...catch<\/code> statement to handle those exceptions.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try Catch Java<\/h2>\n\n\n\n<p>The <code>try...catch<\/code> statement is used to handle exceptions in Java. In order to handle exceptions, a block of code will be placed within a <code>try_catch<\/code> block.<br><\/p>\n\n\n\n<p>When a program encounters a <code>try_catch<\/code> block, the code within the <code>try<\/code> block will be executed. If an exception is raised, the code within the <code>catch<\/code> block will be immediately executed. <code>catch<\/code> blocks must come after a <code>try<\/code> block in a <code>try..catch<\/code> statement.<br><\/p>\n\n\n\n<p>Here\u2019s the syntax for a <code>try_catch<\/code> statement in Java:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>try {\n\t\/\/ Code to run\n} catch (ExceptionType error) {\n\t\/\/ Code to run when exception is raised\n} finally {\n\t\/\/ Code to run even if exception is not raised\n}<\/pre><\/div>\n\n\n\n<p>We\u2019ll talk about the <code>finally<\/code> block later in this tutorial, but for the moment, we\u2019ll focus on the <code>try_catch<\/code> block. Let\u2019s walk through an example to illustrate how this block of code works.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try Catch Java Example<\/h2>\n\n\n\n<p>Say that we are creating a program that uses an array called <code>studentNames<\/code>. We want to print out the fifth name in our studentNames array to the console. However, there are only six students in our class.<br><\/p>\n\n\n\n<p>This would result in an error being raised in our code because we would be referencing a value that did not exist. Here\u2019s an example program that tries to print out the student name with the index value 5 (the sixth student in our class, because index values start at 0):<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class Main {\npublic static void main(String[] args) {\nString[] studentNames = {\"Linda\", \"Greg\", \"Ron\", \"Graham\", \"Alexis\"};\nSystem.out.println(studentNames[5]);\n}<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5\n    at Main.main(Main.java:4)<\/pre><\/div>\n\n\n\n<p>As you can see, our program returned a long error because we tried to reference a value that doesn\u2019t exist.<br><\/p>\n\n\n\n<p>Now, let\u2019s try to use a <code>try...catch<\/code> block to handle our errors. When an error is encountered, our program should print out \u201cThere was an error\u201d, so that we know something has gone wrong. We could use the following code to accomplish this task:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class Main {\npublic static void main(String[] args) {\n\ttry {\nString[] studentNames = {\"Linda\", \"Greg\", \"Ron\", \"Graham\", \"Alexis\"};\nSystem.out.println(studentNames[5]);\n} catch (Exception e) {\n\tSystem.out.println(\"There was an error.\");\n\t\t}\n}<\/pre><\/div>\n\n\n\n<p>Now when we run our code, the following response is returned:<br><\/p>\n\n\n\n<p><code>There was an error.<br><\/code><\/p>\n\n\n\n<p>Additionally, we could specify multiple <code>catch<\/code> blocks. This is useful because it allows us to handle each exception differently.<br><\/p>\n\n\n\n<p>In the example above, an <code>ArrayIndexOutOfBoundsException<\/code> was raised. If we wanted to test for that error specifically, have a custom message printed to the console, and test for other general exceptions, we could use multiple catch statements.<br><\/p>\n\n\n\n<p>Here\u2019s an example of a program that tests for both an <code>ArrayIndexOutOfBoundsException<\/code> and a general Exception and has custom responses for each error:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class Main {\npublic static void main(String[] args) {\n\ttry {\nString[] studentNames = {\"Linda\", \"Greg\", \"Ron\", \"Graham\", \"Alexis\"};\nSystem.out.println(studentNames[5]);\n} catch (ArrayIndexOutOfBoundsException e) {\n\tSystem.out.println(\"ArrayIndexOutOfBoundsException was raised.\");\n} catch (Exception e) {\n\tSystem.out.println(\"There was an error.\");\n\t\t}\n}\n}<\/pre><\/div>\n\n\n\n<p>Now, when we run our program, the following message is printed to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ArrayIndexOutOfBoundsException was raised.<\/pre><\/div>\n\n\n\n<p>This response is returned because an <code>ArrayIndexOutOfBoundsException<\/code> was raised in our program. But if another error occurred, the code in the <code>Exception e<\/code> catch block would run, and the following message would be printed to the console:<br><\/p>\n\n\n\n<p><code>There was an error.<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finally Statement<\/h2>\n\n\n\n<p>The <code>finally<\/code> statement is used to execute a block of code after the <code>try...catch<\/code> block has been executed. The<code>finally<\/code> block is optional, and is always executed if it\u2019s defined. If no exception is raised, the <code>finally<\/code> block is executed after the try block; if an exception is raised, it\u2019s executed after the <code>catch<\/code> block.<br><\/p>\n\n\n\n<p>Let\u2019s use our example from above to illustrate the finally statement in action. Say that we want a message to be printed to the console stating <code>This block has finished executing<\/code>. to tell us that the <code>try_catch<\/code> statement is complete. We could try using the following code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class Main {\npublic static void main(String[] args) {\n\ttry {\nString[] studentNames = {\"Linda\", \"Greg\", \"Ron\", \"Graham\", \"Alexis\"};\nSystem.out.println(studentNames[5]);\n} catch (ArrayIndexOutOfBoundsException e) {\n\tSystem.out.println(\"ArrayIndexOutOfBoundsException was raised.\");\n} catch (Exception e) {\n\tSystem.out.println(\"There was an error.\");\n\t\t} finally {\n\t\t\tSystem.out.println(\"This block of code has finished executing.\");\n\t\t}\n}\n}<\/pre><\/div>\n\n\n\n<p>When we run our code, the following response is returned:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ArrayIndexOutOfBoundsException was raised.<\/pre><\/div>\n\n\n\n<p>This block of code has finished executing.<\/p>\n\n\n\n<p>As you can see, our code raised the <code>ArrayIndexOutOfBoundsException<\/code> exception, as we saw above, and it executed the code within the relevant <code>catch<\/code> block.<br><\/p>\n\n\n\n<p>In our example above, we specified a <code>finally<\/code> statement. So, our code printed out the message <code>This block of code has finished executing<\/code>. after the <code>catch<\/code> block executed.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The <code>try...catch<\/code> block is used in Java to handle exceptions gracefully. The code within the <code>try<\/code> block is executed, and if an exception is raised, the code within the relevant <code>catch<\/code> block is executed. In addition, the <code>finally<\/code> statement is used to execute code after the <code>try...catch<\/code> block has executed, even if no exception was raised.<br><\/p>\n\n\n\n<p>This tutorial discussed how to use the <code>try...catch<\/code> block to handle exceptions in Java and how to use the Java <code>finally<\/code> block. We also walked through an example of both the <code>try...catch<\/code> block and the <code>finally<\/code> statement being used to handle errors.<br><\/p>\n\n\n\n<p>You\u2019re now equipped with the information you need to handle exceptions in Java with confidence!<\/p>\n","protected":false},"excerpt":{"rendered":"Even the best programmers make mistakes in their code. An error could occur because of a typo, an unexpected user input, or for many other reasons which are difficult to track. That\u2019s where exception handling comes in. Good code includes exception handlers, which will respond to an error in code in a predefined way. Exception&hellip;","protected":false},"author":240,"featured_media":13430,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17289],"tags":[],"class_list":{"0":"post-13524","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-java"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Java","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Exception Handling with Try Catch in Java | Career Karma<\/title>\n<meta name=\"description\" content=\"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/java-while-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exception Handling with Try Catch in Java\" \/>\n<meta property=\"og:description\" content=\"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/java-while-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-19T01:03:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:33:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Exception Handling with Try Catch in Java\",\"datePublished\":\"2020-03-19T01:03:46+00:00\",\"dateModified\":\"2023-12-01T10:33:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/\"},\"wordCount\":946,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-using-laptops-3183136-1.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/\",\"name\":\"Exception Handling with Try Catch in Java | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-using-laptops-3183136-1.jpg\",\"datePublished\":\"2020-03-19T01:03:46+00:00\",\"dateModified\":\"2023-12-01T10:33:35+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-using-laptops-3183136-1.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-using-laptops-3183136-1.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-while-loop\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Exception Handling with Try Catch in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Exception Handling with Try Catch in Java | Career Karma","description":"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.","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:\/\/careerkarma.com\/blog\/java-while-loop\/","og_locale":"en_US","og_type":"article","og_title":"Exception Handling with Try Catch in Java","og_description":"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.","og_url":"https:\/\/careerkarma.com\/blog\/java-while-loop\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-03-19T01:03:46+00:00","article_modified_time":"2023-12-01T10:33:35+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Exception Handling with Try Catch in Java","datePublished":"2020-03-19T01:03:46+00:00","dateModified":"2023-12-01T10:33:35+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/"},"wordCount":946,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/java-while-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/","url":"https:\/\/careerkarma.com\/blog\/java-while-loop\/","name":"Exception Handling with Try Catch in Java | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg","datePublished":"2020-03-19T01:03:46+00:00","dateModified":"2023-12-01T10:33:35+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The try catch block is used for exception handling in Java. Learn about exception handling and how to use try, catch, and finally in this article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/java-while-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-using-laptops-3183136-1.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/java-while-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/careerkarma.com\/blog\/java\/"},{"@type":"ListItem","position":3,"name":"Exception Handling with Try Catch in Java"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=13524"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/13430"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=13524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=13524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=13524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}