Click to Play

New Advertising Solution for...
Permuto launched during the Shop.org Annual Summit last week. WebProNews talked with Permuto CEO and Co-Founder Shaukat Shamim to find out about...

Recent Articles

Helpful Java Q&A
If You are appearing for any technical job's interview specially for software and system development you must know the language Java it is considered as the strongest language present in recent times.To make you...

New Sony Computers Now Come With Chrome Installed
Sony and Google would like to confirm that, "it's not what you know, but who you know" is alive and well. At least, that's the official basis for Sony agreeing to make Google's Chrome the default browser in all Vaio...

Understanding And Implementing JAVA String Methods
Strings are very important part of any programming language.Same is the case with Java.There are so many String methods in String class and it will become difficult to explain all of them.I am mainly focusing on...

Understanding A Denial Of Service Attack
I heard on the news today that my favorite social network, Twitter, is being plagued by what they called a "denial of service attack". What on Earth is that? They're forced to not actually get service and it's an attack?

Evolving Business And IT Rules To Match New Demand
Michael Cote of Redmonk had a nice piece on over on his People over Process blog. He made a series of great points about the risk of business and IT people not being aligned - risks to the business and to IT.

Google To Enter The OS Market For Netbooks
Google certainly doesn't rest on its laurels, that's for sure. They are, first and foremost a search engine, but the success of their search business has fathered so many products that aren't search related at...


10.01.09

How To Display Exceptions Through Propagation

By Vaibhav Pandey

There are many important things to remember to catch an exception. For instance one must use catch or finally to catch the thrown exceptions in try block.Also remember that try will never work without either a catch or finally.This is a must follow condition.

So what happens to a exception which is not caught by any of the catch block, of course they keep looking for its handler (its always good to catch 'em) and if they failed to find one they just propagate from one method to the other and end up crashing the program. Whenever an exception is not caught by any catch block in the method then method is said to be ducking the exception. It also means that method passes its course of work to other method to handle the exception. The exception propagation follows call stack. I think you are now grown up and must know what a call stack means. Lets rewind the stack concept that a call stack is a stack where methods are placed in LIFO order based on method call. For example if yo have called method abc() from main() then main() method will be placed at bottom of the stack and the called method abc() will be on top. After the abc finish execution the abc() will be popped from the stack and main() will take pole position.

The above call stack concept also applies to the Exception propagation. Consider we have two methods a() and b(). main() calls a() and after that a() calls method b(). Now suppose the called method b() is facing heat from JVM and it resulted in exception then the exception will look for specific handler,if it failed to either specific handler or a superclass handler then it start to look in the calling method that is a(). Here also it will follow the same procedure and if it again failed it will go to main() method and in the end if it again failed at the bottom of the stack then mate its ultimate law of nature that it has to die a horrible death,or it will produce a complete stack trace of the exception. Following figure shows how call stack woks and exception propagate"-




MyFax Internet Faxing.
Anywhere your business takes you.
Get Your Free Trial Now

Make it even more clear by considering the following example:-

public class Exceptionpropagation{
public static void main(String[] a){
domore();
}
public void domore(){
doevenmore();
}
public void doevenmore(){
int x=10/0;
}
}

The produced will be in the order of stack call that is from code it is clear that the exception is generated from doevenmore() so it will be listed on top of stack trace and following the stack trace you can find out where actually the exception has happened.

The resulting exception would be and its stack trace :-
Exception in thread "main"
java. lang. ArithmeticException: / by zero
at Exceptionpropagation. doevenmore(Exceptionpropagation. java:13)
at Exceptionpropagation. domore(Exceptionpropagation. java:10)
at Exceptionpropagation. main(Exceptionpropagation. java:7)
Process Exit. . .

Comments


About the Author:
Vaibhav Pandey got offered employment from an Indian Multinational IT Company. He is 21 years old. He has a huge interest in Java programming and has liked it from his study days. Vaibhav loves to blog and share his experiences and thoughts. He now resides in Lucknow, a state capital in India. Check out his blog at http://javatutorialsworld.blogspot.com.
About SysAdminNews
SysAdminNews is a collection of articles, news and commentary designed to keep system administrators informed about the latest trends impacting their profession. Updates and Advice for System Administrators





SysAdminNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
SysAdminNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com





-- SysAdminNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2009 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


Database Forum Updates and Advice for System Administrators SysAdminNews News Archives About Us Feedback SysAdminNews.com About Article Archive News Downloads WebProWorld Forums iEntry Advertise Contact Jayde