<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Java%2FC3%2FCustom-Exceptions%2FEnglish-timed</id>
		<title>Java/C3/Custom-Exceptions/English-timed - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Java%2FC3%2FCustom-Exceptions%2FEnglish-timed"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Java/C3/Custom-Exceptions/English-timed&amp;action=history"/>
		<updated>2026-04-05T21:55:58Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Java/C3/Custom-Exceptions/English-timed&amp;diff=39012&amp;oldid=prev</id>
		<title>Jyotisolanki at 06:55, 14 September 2017</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Java/C3/Custom-Exceptions/English-timed&amp;diff=39012&amp;oldid=prev"/>
				<updated>2017-09-14T06:55:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 06:55, 14 September 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 284:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 284:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|&amp;#160; 06: 56&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|&amp;#160; 06:56&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|Verify the '''custom exception class'''. &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|Verify the '''custom exception class'''. &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jyotisolanki</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Java/C3/Custom-Exceptions/English-timed&amp;diff=39011&amp;oldid=prev</id>
		<title>Jyotisolanki: Created page with &quot;{| border=1 | &lt;center&gt;Time&lt;/center&gt; | &lt;center&gt;Narration&lt;/center&gt;  |- |  00:01 |  Welcome to the spoken tutorial on''' custom exceptions.'''  |- |  00:05 |  In this tutorial we...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Java/C3/Custom-Exceptions/English-timed&amp;diff=39011&amp;oldid=prev"/>
				<updated>2017-09-14T06:55:06Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{| border=1 | &amp;lt;center&amp;gt;Time&amp;lt;/center&amp;gt; | &amp;lt;center&amp;gt;Narration&amp;lt;/center&amp;gt;  |- |  00:01 |  Welcome to the spoken tutorial on&amp;#039;&amp;#039;&amp;#039; custom exceptions.&amp;#039;&amp;#039;&amp;#039;  |- |  00:05 |  In this tutorial we...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
| &amp;lt;center&amp;gt;Time&amp;lt;/center&amp;gt;&lt;br /&gt;
| &amp;lt;center&amp;gt;Narration&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:01&lt;br /&gt;
|  Welcome to the spoken tutorial on''' custom exceptions.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:05&lt;br /&gt;
|  In this tutorial we will learn about:  '''Custom exceptions '''and  Usage of '''throw''' and '''throws keywords'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:14&lt;br /&gt;
|To record this tutorial, I am using :'''Ubuntu Linux 16.04 OS''' '''JDK 1 .7 '''and '''Eclipse 4.3.1 '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:26&lt;br /&gt;
|  To follow this tutorial, you must have basic knowledge of '''Exceptions Handling '''in''' Java.''' If not, for relevant''' Java '''tutorials, please visit the link shown.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:38&lt;br /&gt;
|  First let us learn about '''custom exceptions'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:42&lt;br /&gt;
| '''Custom exception''' is a '''user defined exception class'''.  It is usually created as '''checked exceptions.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:51&lt;br /&gt;
|It is used to customize the '''exception''' according to user need. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:57&lt;br /&gt;
|  Now we will open''' eclipse''' and create a new '''project''' called''' CustomExceptionDemo.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:04&lt;br /&gt;
|Inside this '''project''' we will create the necessary '''classes''' to demonstrate '''custom exceptions.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:11&lt;br /&gt;
|  We will create a new '''class InvalidMarkException.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:15&lt;br /&gt;
|  To make this as a type of '''exception class''', it should be a '''subclass''' of '''Java exception class'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:22&lt;br /&gt;
|To do so, type''' extends Exception'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:27&lt;br /&gt;
|  Click on '''Source''' menu and then select '''Generate constructors from Superclass'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:34&lt;br /&gt;
|  Now click on '''Deselect All''' button in the right hand side.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:38&lt;br /&gt;
|  Then select the '''constructor''' with a '''single string argument''' and click on '''OK''' button at the bottom.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:45&lt;br /&gt;
|This '''string argument''' can be used to customize the message shown when this '''exception''' occurs.&amp;lt;nowiki&amp;gt;&amp;lt;&amp;lt;PAUSE&amp;gt;&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:52&lt;br /&gt;
|  Let us add another '''class''' named '''StudentMarks.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:57&lt;br /&gt;
|  Then type the following code.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:00&lt;br /&gt;
|This '''class''' contains only one '''variable''' named '''marks.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:04&lt;br /&gt;
|This '''constructor''' initializes the value of '''marks.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:09&lt;br /&gt;
|  Let us now add a '''method''' to validate the marks.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:13&lt;br /&gt;
|The normal range of marks is from 0 to 100.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:18&lt;br /&gt;
|If '''marks less than 0 or greater than 100''' is processed, '''InvalidMarkException''' will be thrown.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:25&lt;br /&gt;
|For this, we need to use the '''throw keyword''' explicitly to throw a '''custom exception'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:33&lt;br /&gt;
|If the mark is a valid one, the message '''“Entry OK” '''will be displayed. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:39&lt;br /&gt;
|  We can see that there is an error '''InvalidMarkException.''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:43&lt;br /&gt;
|Let us check and resolve it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:46&lt;br /&gt;
|  So click on the error and double click '''“Add throws declaration'''”.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:51&lt;br /&gt;
|We can see that the error disappears once the '''“throws InvalidMarkException”''' is added to the '''method signature.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:00&lt;br /&gt;
|  Here we can see that the '''throws keyword''' is used along with '''methods'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:06&lt;br /&gt;
|  It indicates that the '''method''' will raise the '''specified exception.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:11&lt;br /&gt;
|  We have to provide the '''exception handling''' code when such a '''method''' is called.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:16&lt;br /&gt;
|  Next, let us perform a '''file access operation''' which will raise a '''FileNotFoundException'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:23&lt;br /&gt;
|So type the following code to create an instance of a '''FileReader class'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:29&lt;br /&gt;
|  '''Eclipse''' will show some errors as we have not imported the corresponding '''Java packages.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:36&lt;br /&gt;
|To rectify the same, click on the error and then double click '''import 'FileReader' (java.io).'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:44&lt;br /&gt;
|We will learn about '''package''' and its usage in detail in a later tutorial.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:50&lt;br /&gt;
|To allow '''fr '''to access a file called''' Marks''' which is located in the home folder, type the following code.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:59&lt;br /&gt;
|The path shown here is to be replaced with that of your system's home folder.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:05&lt;br /&gt;
|  An error shows that this line of code can raise a '''FileNotFoundException.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:10&lt;br /&gt;
|We can resolve it by adding this exception in the '''throws clause'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:16&lt;br /&gt;
|  We can see that '''FileNotFoundException''' is also added to the '''throws clause'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:22&lt;br /&gt;
|We can handle multiple '''exceptions''' using '''throws''' as shown here.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:28&lt;br /&gt;
|  We will now create the '''main method''' inside the '''StudentMarks class''' and verify the results.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:34&lt;br /&gt;
|  Here we create an object '''m1''' initialized with 40 as the value for '''marks.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:41&lt;br /&gt;
|In04: the next line we invoke the method '''validate''' using the object '''m1.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:47&lt;br /&gt;
|  We can see that there is an error when the '''validate method''' is invoked.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:52&lt;br /&gt;
|It says that this '''method''' will raise the  '''InvalidMarkException''' and '''FileNotFoundException'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:59&lt;br /&gt;
|  To resolve the error, we can add '''throws clause''' to '''main method''' as we did earlier&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:05&lt;br /&gt;
|But it is recommended to use '''try''' and '''catch block.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:10&lt;br /&gt;
|So, double click '''Surround with try/catch'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:14&lt;br /&gt;
|Now the necessary '''try-catch blocks''' are added and the '''exception''' has been handled.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:20&lt;br /&gt;
|  Now let us run this program.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:23&lt;br /&gt;
|  It displays “Entry OK” and “rest of the code”.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:27&lt;br /&gt;
|This happens because the value of '''marks''' 40 is a valid entry.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:32&lt;br /&gt;
|  Let us now change the value to -10 which is an invalid entry. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:37&lt;br /&gt;
|  We will run the program again.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:40&lt;br /&gt;
|  Now we can see that the '''InvalidMarkException''' is thrown as -10 is an invalid entry.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:47&lt;br /&gt;
|Since we have handled the '''exception''', we can see the message “rest of the code” &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:53&lt;br /&gt;
|Instead if we use '''“throws” clause''', this message “rest of the code” will not be printed. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:00&lt;br /&gt;
|Also the program will be terminated.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:03&lt;br /&gt;
|So it is better to use a '''try catch block''' when a '''method''' is called inside the '''main method'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:10&lt;br /&gt;
|With this we come to the end of this tutorial.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:13&lt;br /&gt;
| Let us summarize.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:15&lt;br /&gt;
|In this tutorial we have learned about :What is a '''Custom Exception''' Usage of '''throw''' and '''throws keywords''' How to create and use '''custom exceptions'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:26&lt;br /&gt;
|  As an assignment :Create a '''custom exception class''' called '''InvalidAgeException''' &lt;br /&gt;
   &lt;br /&gt;
|-&lt;br /&gt;
|  06:33&lt;br /&gt;
| Create another '''class Age''' and create a '''constructor''' to initialize the value of age&lt;br /&gt;
  &lt;br /&gt;
|-&lt;br /&gt;
|  06:39&lt;br /&gt;
|  Also create a '''method validate''' to throw an '''exception''' if the age is less than 18&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:45&lt;br /&gt;
|  Create objects inside the '''main method''' and invoke the '''validate() method'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:51&lt;br /&gt;
|Provide '''exception handling''' using '''try-catch blocks''' wherever required.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06: 56&lt;br /&gt;
|Verify the '''custom exception class'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:00&lt;br /&gt;
|  The video at the following link summarizes the''' Spoken Tutorial Project.''' Please download and watch it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:06&lt;br /&gt;
|  The''' Spoken Tutorial Project Team''' Conducts workshops using spoken tutorials and Gives certificates on passing the online tests For more details, please write to us.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:18&lt;br /&gt;
|  '''Spoken Tutorial Project''' is funded by the NMEICT, MHRD, Government of India. More information on this mission is available at the link shown.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:29&lt;br /&gt;
|  This script has been contributed by: '''Department of Information Technology, Amal Jyothi College of Engineering'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:36&lt;br /&gt;
| This is Priya from IIT Bombay, signing off. Thanks for joining.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Jyotisolanki</name></author>	</entry>

	</feed>