• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Reference Variable casting ... compile Errors vs Runtime errors  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi :
can you please tell me the rule to know wheather an upcast or a downcast will produce a compile error OR a runtime error , for exemple :





i tought the it will produce "howl woof followed by an exception " BUT it produce a compile error at line 15 ..???
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

karim amrani wrote:
i tought the it will produce "howl woof followed by an exception " BUT it produce a compile error at line 15 ..???


welcome to ranch!!
go to edit and use code tags for writing codes.

because dog class doesn't know about the sniff() method, so it's a compiler error.
why do you think it should give a run-time exception?
 
karim amrani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because i dont know how to determines wich type of error it will raise ...so the MethodNotFoundException comes in my head and thought it's probably this .... that's why i asked you about A FIRM RULE to know if an error will be catched by the complier or while excution ..
thanks for the code-tag tip and Sorry for my english
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no problem friend.
if compiler didn't able to find something that you are referring or using or some kind of syntactical mistake ,then it will gives you a compiler error.
exception will be thrown when your program satisfies the compiler needs,but some illegal behavior like illegal reference or argument you are using cause your program to stop at run time.
 
Hot dog! An advertiser loves us THIS much:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!