• 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

throw assertion error

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


what will be the output ?
a throwable is throwen by main
or an exception is throwen by main
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What has the output when you ran it?
 
Heba Mahmoud
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the output is
Exception in thread "main" java.lang.AssertionError

i know that error can't be handle by exception handler. but what i understand from output that the assertionerror is an exception
that means that it is may be a child for excepton class so why catch clause fails to handle.

and also ....at the same time i wondered why it cause an excption not an error
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.AssertionError is a Child of java.lang.Error and not of java.lang.Exception and because of that it is not caught in your catch-block.
 
Heba Mahmoud
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so the right answer will be a throwable is thrown by main

thanks
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saying specifically it will be an Error not throwable. But because throwable is parent of both Error and Exception so in case of both you can say that if is a throwable but actually it will be Error or Exception.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error and RuntimeException are unchecked exceptions so the compiler doesn't care whether you catch them, declare them or ignore them. Changing line 15 on your code to say (Error e) will bear out what Wouter has said.

 
reply
    Bookmark Topic Watch Topic
  • New Topic