• 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

Identifying an exception or error?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I know the concept of exceptions. But when I solve questions and if there are both (error and exception) in the choice of answers, I find it difficult to identify.

Are there any guidelines to decide when whould the code throw an exception and when would the code throw an error?

Thanks
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
an error is something when your code broke the basic syntax of java language specifications, and exception are definitely not an error ! So I dont think , there will be any difficulty in finding the difference between them .

If you are not satisfied with reply, tell us in detail , What exactly you want !
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error - it will mainly not occur because of logic applied in the program. It will occur always at runtime and some problem jvm has come accross. Like StackOverFlowError - when data loaded in heap exceeds the size of heap.
ClassNotDefoundError - when problem while loading a class.

Whereas exceptions will be mainly because of programming fault. Also exceptions once caught, application can continue runnig , but this is not the case with error.

MAinly in questions exceptions will be the answer as you cannot identify when an error can occur.
 
George Gates
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chowdry,

Exception:
1) A programmer expects that inside his/her program that something might go wrong and tries to handle the exception if that happens
2) Exception can be of two types Checked and Unchekced and checked exception can be handled or declared in the program
3) You can pass the exception to the method which it called if the current method doesn't handle the exception. This is called ducking the exception to main().


Error:
1) Programmer doesn't know whether the error is going to happen or not say for example if you are reading a file from server and in case the server shut down these are called error.
2) You cannot handle or declare an error in you program.

Both Exception and error are from java.lang.Throwable class.

Hope this clarifies your doubt.
 
George Gates
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Justin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic