• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why not ArithmeticException thrown?

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


ans=An assertionEROR with -2 as message is thrown.

My question is when line 2 is called ,why its not throwing assertion error at line 1?

Thanks
Sandhya
[ March 13, 2008: Message edited by: sandhi mridul ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandhi,

You will get an ArithmeticException if you try to divide by 0 at line 1.
0/2 = 0, no ArithmeticException.

Thanks,
Sheryl.
[ March 13, 2008: Message edited by: Sheryl Pinto ]
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When line 2 is executed and T1.test() is called with int value 0 the first statement attemps to divide 0 by 2, which is perfectly legal.
Dividing 0 by an arbitry value is legal and will always result in 0.
Dividing an arbitrary value by 0 is not legal and will always result in an java.lang.ArithmeticException being thrown.
I believe you have the two mixed up.

Edit: Sheryl beat me to it
[ March 13, 2008: Message edited by: Jelle Klap ]
 
sandhi mridul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh yaa.
sorry for overlooking.
Thanks for all your reply.
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic