• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throw assertion error

 
Heba Mahmoud
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


what will be the output ?
a throwable is throwen by main
or an exception is throwen by main
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
so the right answer will be a throwable is thrown by main

thanks
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic