{"id":4472,"date":"2014-03-30T11:23:37","date_gmt":"2014-03-30T11:23:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/using-super-in-a-derived-class-constructor-when-base-class-requires-exceptions-to-be-caught-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:23:37","modified_gmt":"2014-03-30T11:23:37","slug":"using-super-in-a-derived-class-constructor-when-base-class-requires-exceptions-to-be-caught-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/using-super-in-a-derived-class-constructor-when-base-class-requires-exceptions-to-be-caught-collection-of-common-programming-errors\/","title":{"rendered":"Using Super in a Derived Class Constructor When Base Class Requires Exceptions to be Caught-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to derive a class B to a new class C in Java. The base class constructor requires that unreported exceptions must be thrown or caught. But if I try to put super(..) inside a try\/catch then I&#8217;m told that the call to super must be the first statement in the constructor. Does anyone know a way around this?<\/p>\n<pre><code>public class C extends B\n{\n   \/\/Following attempt at a constructor generates the error \"Undeclared exception E; must be caught or declared\n   \/\/to be thrown\n    public C(String s)\n    { \n         super(s);\n    }\n\n    \/\/But the below also fails because \"Call to super must be the first statement in constructor\"\n    public C(String s)\n    {\n         try\n         {\n              super(s);\n         }\n          catch( Exception e)\n         {\n         }\n     }\n }\n<\/code><\/pre>\n<p>Many thanks, Chris<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to derive a class B to a new class C in Java. The base class constructor requires that unreported exceptions must be thrown or caught. But if I try to put super(..) inside a try\/catch then I&#8217;m told that the call to super must be the first statement in the constructor. Does anyone [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4472","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4472"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4472\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}