<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.omnivision.website/index.php?action=history&amp;feed=atom&amp;title=3.6.2_Exception_Handling_%28try-catch%29</id>
	<title>3.6.2 Exception Handling (try-catch) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.omnivision.website/index.php?action=history&amp;feed=atom&amp;title=3.6.2_Exception_Handling_%28try-catch%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.omnivision.website/index.php?title=3.6.2_Exception_Handling_(try-catch)&amp;action=history"/>
	<updated>2026-06-15T08:22:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://wiki.omnivision.website/index.php?title=3.6.2_Exception_Handling_(try-catch)&amp;diff=137&amp;oldid=prev</id>
		<title>Mr. Goldstein: Created page with &quot;=== 3.6.2 Exception Handling (try-catch) === Imagine you&#039;re a robot trying to open a file on a computer. What if the file isn&#039;t there? Instead of just stopping and saying &quot;Error!&quot;, you want the robot to be polite and say, &quot;I couldn&#039;t find the file, would you like me to try again?&quot;  &#039;&#039;&#039;Exception Handling&#039;&#039;&#039; is a programming technique that allows your program to &#039;&#039;&#039;gracefully deal with runtime errors&#039;&#039;&#039; (also called &quot;exceptions&quot;). Instead of crashing when something unexpec...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.omnivision.website/index.php?title=3.6.2_Exception_Handling_(try-catch)&amp;diff=137&amp;oldid=prev"/>
		<updated>2025-07-08T13:05:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=== 3.6.2 Exception Handling (try-catch) === Imagine you&amp;#039;re a robot trying to open a file on a computer. What if the file isn&amp;#039;t there? Instead of just stopping and saying &amp;quot;Error!&amp;quot;, you want the robot to be polite and say, &amp;quot;I couldn&amp;#039;t find the file, would you like me to try again?&amp;quot;  &amp;#039;&amp;#039;&amp;#039;Exception Handling&amp;#039;&amp;#039;&amp;#039; is a programming technique that allows your program to &amp;#039;&amp;#039;&amp;#039;gracefully deal with runtime errors&amp;#039;&amp;#039;&amp;#039; (also called &amp;quot;exceptions&amp;quot;). Instead of crashing when something unexpec...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== 3.6.2 Exception Handling (try-catch) ===&lt;br /&gt;
Imagine you&amp;#039;re a robot trying to open a file on a computer. What if the file isn&amp;#039;t there? Instead of just stopping and saying &amp;quot;Error!&amp;quot;, you want the robot to be polite and say, &amp;quot;I couldn&amp;#039;t find the file, would you like me to try again?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Exception Handling&amp;#039;&amp;#039;&amp;#039; is a programming technique that allows your program to &amp;#039;&amp;#039;&amp;#039;gracefully deal with runtime errors&amp;#039;&amp;#039;&amp;#039; (also called &amp;quot;exceptions&amp;quot;). Instead of crashing when something unexpected happens, you can &amp;quot;catch&amp;quot; the error and tell your program what to do about it.&lt;br /&gt;
&lt;br /&gt;
The most common way to do this is using a &amp;lt;code&amp;gt;try-catch&amp;lt;/code&amp;gt; block (or &amp;lt;code&amp;gt;try-except&amp;lt;/code&amp;gt; in Python).&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;How &amp;lt;code&amp;gt;try-catch&amp;lt;/code&amp;gt; Works:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; block:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#* You put the code that &amp;#039;&amp;#039;might&amp;#039;&amp;#039; cause an error inside the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; block.&lt;br /&gt;
#* It&amp;#039;s like saying, &amp;quot;TRY to do this risky thing.&amp;quot;&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;catch&amp;lt;/code&amp;gt; block (or &amp;lt;code&amp;gt;except&amp;lt;/code&amp;gt; in Python):&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#* If an error (an &amp;quot;exception&amp;quot;) &amp;#039;&amp;#039;does&amp;#039;&amp;#039; happen inside the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; block, the program immediately jumps to the &amp;lt;code&amp;gt;catch&amp;lt;/code&amp;gt; block.&lt;br /&gt;
#* The &amp;lt;code&amp;gt;catch&amp;lt;/code&amp;gt; block contains the code that tells your program &amp;#039;&amp;#039;&amp;#039;how to handle the error.&amp;#039;&amp;#039;&amp;#039; This might involve:&lt;br /&gt;
#** Printing an error message to the user.&lt;br /&gt;
#** Logging the error for the programmer to see later.&lt;br /&gt;
#** Trying an alternative action.&lt;br /&gt;
#** Asking the user for new input.&lt;br /&gt;
#* You usually specify the &amp;#039;&amp;#039;type&amp;#039;&amp;#039; of error you want to catch (e.g., a &amp;quot;file not found&amp;quot; error, or a &amp;quot;division by zero&amp;quot; error).&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example (Java concept):&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 &amp;lt;code&amp;gt;// Imagine we&amp;#039;re trying to divide two numbers&lt;br /&gt;
 int numerator = 10;&lt;br /&gt;
 int denominator = 0; // Uh oh, this will cause a division by zero error!&lt;br /&gt;
 &lt;br /&gt;
 try {&lt;br /&gt;
     // TRY to do this calculation&lt;br /&gt;
     int result = numerator / denominator;&lt;br /&gt;
     System.out.println(&amp;quot;Result: &amp;quot; + result); // This line won&amp;#039;t run if an error happens above&lt;br /&gt;
 } catch (ArithmeticException e) { // CATCH a specific type of error: ArithmeticException (like division by zero)&lt;br /&gt;
     // If the error happens, do THIS instead of crashing&lt;br /&gt;
     System.out.println(&amp;quot;Error: Cannot divide by zero!&amp;quot;);&lt;br /&gt;
     // You can also print details about the error:&lt;br /&gt;
     // System.out.println(&amp;quot;Error details: &amp;quot; + e.getMessage());&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 System.out.println(&amp;quot;Program continues after the try-catch block.&amp;quot;);&lt;br /&gt;
 // Output:&lt;br /&gt;
 // Error: Cannot divide by zero!&lt;br /&gt;
 // Program continues after the try-catch block.&amp;lt;/code&amp;gt;&lt;br /&gt;
Without the &amp;lt;code&amp;gt;try-catch&amp;lt;/code&amp;gt; block, the program would have crashed when it tried to divide by zero. With it, it handles the error gracefully and continues running.&lt;br /&gt;
&lt;br /&gt;
Exception handling is a powerful way to make your programs more robust and user-friendly, preventing unexpected crashes and providing helpful feedback.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Bibliography:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;GeeksforGeeks - Exception Handling in Java&amp;#039;&amp;#039;&amp;#039;: [https://www.geeksforgeeks.org/java/exceptions-in-java/ https://www.geekshttps://www.geeksforgeeks.org/java/exceptions-in-java/forgeeks.org/java/exceptions-in-java/]&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;W3Schools - Python Try Except&amp;#039;&amp;#039;&amp;#039;: https://www.w3schools.com/python/python_try_except.asp&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Wikipedia - Exception handling&amp;#039;&amp;#039;&amp;#039;: https://en.wikipedia.org/wiki/Exception_handling&lt;/div&gt;</summary>
		<author><name>Mr. Goldstein</name></author>
	</entry>
</feed>