aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception?" Watch "Exception?" New topic
Author

Exception?

Hennry Smith
Greenhorn

Joined: Jan 21, 2011
Posts: 26
Define An Exception Called "NoMatchException" That Is Thrown When A String Is Not Equal To "Symbiosis". Write A Java Program That Uses This Exception?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

Sounds straight-forward enough. What's the problem?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hennry Smith
Greenhorn

Joined: Jan 21, 2011
Posts: 26

why we have used "printStacktrace()" in this program.....???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

To print the stack trace.
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281


are you aware of stack trace ?
Whenever a thread calls a method it put it into its stack and when an Exception get thrown it unwind this stack until Exception get caught or until thread dies. this stack trace is useful to find out where exactly problem lies. just run your program with some other String "Symbiosis" and you will know why need to print stack trace.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
Hennry Smith
Greenhorn

Joined: Jan 21, 2011
Posts: 26
Javin Paul wrote:
are you aware of stack trace ?
Whenever a thread calls a method it put it into its stack and when an Exception get thrown it unwind this stack until Exception get caught or until thread dies. this stack trace is useful to find out where exactly problem lies. just run your program with some other String "Symbiosis" and you will know why need to print stack trace.


in the above program we have made a "comparestring" method and passed a string parameter to it and now if the string str matched with "Symbiosis" it prints string are equal otherwise it throws a exception. now in main method we have called "comparestring" with "arg[0]" as argument......how we have used arg[0] to match it with "Symbiosis" and please explain the below code....according to me we have made a "nomatchexception" class and extends exception class....
then we have declared a nomatchexception method and passed strind parameter to it and then why we have super(meaasge) here......i know super is used to call the parent class...but here what message it will print here.....???



also if i am wrong somewhere..please tell....
thank you so much for your previous reply.....
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281

There is nothing wrong in your code related to Creating Exception and using it.

you need to understand the usage of Exception , when an Exception thrown it indicates an error and to resolve that error you need to find Why error occurred and at which line of code error occurs ? here printstacktrace() comes in picture it will tell you at which line of your code error has occurred i.e. from which line Exception gets thrown .

Just run your program with input String as "Javin" and see what output comes. as per your code it will throw an Exception "nomatchexception" if you comment this line Exception will be thrown but stacktrace will not be printed.

I hope this help you.

Javin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception?