java - At subclass Compilation Error: Unreachable catch block for CloneNotSupportedException -


in superclass, when override clone() method there no problem.

public class superclass implements serializable, cloneable {     public object clone() {         try {             return super.clone();         } catch (clonenotsupportedexception e) {             return null;         }     } } 

when override clone() method in subclass doing same (copy , paste clone() method super class) it's showing compilation error

public class subclass extends superclass implements serializable, cloneable {     public object clone() {         try {             return super.clone();         } catch (clonenotsupportedexception e) {             return null;         }     } } 

compilation error in subclasss @ line containing catch:

unreachable catch block clonenotsupportedexception. exception never thrown try statement body

again, if remove method clone() superclass subclass wont show error.

where gap of understanding?

if superclass's clone catches clonenotsupportedexception , doesn't throw it, subclass doesn't have catch it, since can never thrown try block of subclass's clone().

when remove clone() superclass, subclass calls object's clone() has throws clonenotsupportedexception clause. therefore have catch exception (or add throws clonenotsupportedexception method).


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -