<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Java Programming Forum - Learn Java Programming - Blogs - Java Exception</title>
		<link>http://www.java-forums.org/blogs/java-exception/</link>
		<description>Java Programming Forum - Learning Java easily</description>
		<language>en</language>
		<lastBuildDate>Tue, 21 May 2013 06:12:09 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.java-forums.org/images/misc/rss.jpg</url>
			<title>Java Programming Forum - Learn Java Programming - Blogs - Java Exception</title>
			<link>http://www.java-forums.org/blogs/java-exception/</link>
		</image>
		<item>
			<title>User defined exception</title>
			<link>http://www.java-forums.org/blogs/java-exception/766-user-defined-exception.html</link>
			<pubDate>Sun, 08 Jan 2012 11:01:14 GMT</pubDate>
			<description>You can customize and write your own user defined exceptions. Following class extends the Exception class and writes a new “MyException” which is...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">You can customize and write your own user defined exceptions. Following class extends the Exception class and writes a new “MyException” which is thrown at some point in your code.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code:  This is an example of user defined exception</div>

	<pre class="brush: java">public class MyException extends Exception {
/* class definition of constructors goes here */
public MyException() {
super();
}
public MyException (String errorMessage) {
super (errorMessage);
}
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Exception</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-exception/766-user-defined-exception.html</guid>
		</item>
		<item>
			<title>Exception handling best practices</title>
			<link>http://www.java-forums.org/blogs/java-exception/765-exception-handling-best-practices.html</link>
			<pubDate>Sun, 08 Jan 2012 10:58:30 GMT</pubDate>
			<description>Following are the best practices when catching and handling exceptions in your java code. 
 
•	Do not catch “Exception” directly in your code. Java...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Following are the best practices when catching and handling exceptions in your java code.<br />
<br />
•	Do not catch “Exception” directly in your code. Java exception handling is not polymorphic. If you catch Exception, it can catch IOException or any other descendent type. <br />
<br />
<div style="text-align: center;"><img src="http://www.java-forums.org/attachments/java-software/2587d1326020248-safe-safedesktop-2-0-62.jpg" border="0" alt="Name:  62.JPG
Views: 519
Size:  35.3 KB" class="thumbnail" style="float:CONFIG" /><br />
<br />
<b>Catching Exceptions</b></div><br />
•	Exception handling supports the stack trace of any error in your code. Always throw an exception early in your code to make this trace more accurate. <br />
•	Always catch a checked exception late in your code.</blockquote>

]]></content:encoded>
			<dc:creator>Java Exception</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-exception/765-exception-handling-best-practices.html</guid>
		</item>
		<item>
			<title>Java error handling</title>
			<link>http://www.java-forums.org/blogs/java-exception/764-java-error-handling.html</link>
			<pubDate>Sun, 08 Jan 2012 10:56:07 GMT</pubDate>
			<description>When a hard failure or link failure occurs in virtual machine, JVM throws an Error. These Errors are not caught by the typical java programs. 
 
When...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">When a hard failure or link failure occurs in virtual machine, JVM throws an Error. These Errors are not caught by the typical java programs.<br />
<br />
When a problem occurs in the code, an Exception is thrown and is caught by the program explicitly. Base class of all Exception classes is Exception class. All other are derived classes. Below image shows a complete hierarchy of the exceptions in java.<br />
<div style="text-align: center;"><br />
<img src="http://www.java-forums.org/attachments/java-software/2586d1326020110-jscl-meditor-2-1_01-62.jpg" border="0" alt="Name:  62.JPG
Views: 440
Size:  16.3 KB" class="thumbnail" style="float:CONFIG" /></div><br />
<b><div style="text-align: center;">Throwable and subclasses</div></b><br />
<br />
A RuntimeException occurs within JVM like NullPointerException. Catching these exceptions in the code increases performance issues but makes the code more reliable. All the exceptions should catch in the above hierarchy.  Also you can customize these exceptions and can write your own custom exceptions.</blockquote>

]]></content:encoded>
			<dc:creator>Java Exception</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-exception/764-java-error-handling.html</guid>
		</item>
		<item>
			<title>Basics of Exceptions</title>
			<link>http://www.java-forums.org/blogs/java-exception/611-basics-exceptions.html</link>
			<pubDate>Tue, 29 Nov 2011 02:09:47 GMT</pubDate>
			<description>One of the key aspects of programming is understanding how to handle exceptions. An exception is a problem that prevents the continuation of the...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">One of the key aspects of programming is understanding how to handle exceptions. An exception is a problem that prevents the continuation of the current method or scope. It’s important to distinguish an exceptional condition from a normal problem, in which you have enough information in the current context to somehow cope with the difficulty. With an exception, you cannot continue processing because you lack the information necessary to address the problem in its current context. The only recourse you have, is to jump out of the current context and relegate that problem to a another (higher) context. <br />
<br />
When you throw an exception, there are several things taking place. First, the exception object is created on the heap, with new keyword. The current path of execution is stopped and the reference for the exception object is ejected from the current context. At this point the exception-handling mechanism kicks in and you define the context for the exception to be handled in a manner in a way that is safe for the program and in which can you provide appropriate information to the user. The means of appropriate means Java has for this is what is called an exception handler. An exception handler is used to recover from a problem so the program can either try another tack or just continue.<br />
<br />
The way you do this is by throwing an exception. What throwing an exception does is to put the error into a larger context by creating an object representing your information and &quot;throwing&quot; it out of its existing context. Here is an example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">if(t == null) 
	throw new NullPointerException();</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 In the example has an object reference called t. In this situation because it hasn’t been initialized it has a null reference. Because of that it is impossible to go further with processing so a NullPointerException is thrown. Exceptions allow you to force the program to stop and tell you what went wrong, or (ideally) force the program to deal with the problem and return to a stable state.</blockquote>

]]></content:encoded>
			<dc:creator>Java Exception</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-exception/611-basics-exceptions.html</guid>
		</item>
		<item>
			<title>Catching an Exception</title>
			<link>http://www.java-forums.org/blogs/java-exception/610-catching-exception.html</link>
			<pubDate>Tue, 29 Nov 2011 02:07:35 GMT</pubDate>
			<description>Following on from our previous tip on exceptions, in this tip we will look at catching an exception. One of the key concepts to understand is the...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Following on from our previous tip on exceptions, in this tip we will look at catching an exception. One of the key concepts to understand is the concept of a guarded region. It is a section of code that might produce exceptions and is followed by the code to handle a particular exception. They are often grouped into all the possible exceptions for a particular method or piece of code.<br />
<br />
The try block<br />
The first part of the region is the try block. This is when you’re inside a method and you throw an exception or if another method is called and throws an exception, the method will then exit in the process of throwing the occurring exception. <br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">try {
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 // Code that might generate exceptions<br />
<br />
When you are catching and handling exceptions, you put everything in a try block and capture all the exceptions in one place. This means your code is much easier to write and read because the goal of the code is not confused with the error checking.<br />
Exception handlers<br />
Once the exception is thrown, you setup blocks of code to handle the different type of exceptions that can take place in your code. This block is called an exception handler. You setup one for every exception type you want to catch. Exception handlers immediately follow the try block and are denoted by the keyword catch:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">try {
.......
} catch(Exception1 ex1)|{ 
	// Handle exceptions of Type1
} 
catch(Exception2 ex2) { 
	// Handle exceptions of Type2
} catch(Exception3 ex3) {
	// Handle exceptions of Type3 // etc...
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Termination vs. resumption<br />
There are two basic models in exception-handling theory. Java supports termination,  in which you you decide that the error is too critical to continue. The alternative is called resumption. In this case, the exception handler is does something to rectify the situation, and then the method is retried, presuming success the second time. If you want resumption, it means you still hope to continue execution after the exception is handled. Resumption code is difficult to write and maintain since you need to be aware of where the exception is thrown and handle the exception in a very precise manner.</blockquote>

]]></content:encoded>
			<dc:creator>Java Exception</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-exception/610-catching-exception.html</guid>
		</item>
	</channel>
</rss>
