• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define An Exception Called "NoMatchException" That Is Thrown When A String Is Not Equal To "Symbiosis". Write A Java Program That Uses This Exception?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds straight-forward enough. What's the problem?
 
Hennry Smith
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why we have used "printStacktrace()" in this program.....???
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To print the stack trace.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Hennry Smith
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic