• Post Reply Bookmark Topic Watch Topic
  • New Topic

exception caught  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In above even though exception is handled in catch block still it shows an error?reason
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Base class includes a method called "get" that is declared as throwing an Exception, so it must be handled or thrown by the caller of that method. The caller is your static main routine, so it must handle or throw it. The reason for your error is that it doesn't do either.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The get method is throwing an exception and b.get() is neither catching it nor throwing it too. It has to do one of those.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:Your Base class includes a method called "get" . . .
No, it doesn't. It contains half a method, which won't compile.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Stevens Miller wrote:Your Base class includes a method called "get" . . .
No, it doesn't. It contains half a method, which won't compile.

Not seeing that, Campbell. If I comment out the b.get() call, it does compile for me. Are you missing the closing curly bracket at the very end? He has two of them together on the same line.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I think I was mistaken; what with the crappy indentation I missed the {} at the end of the declaration. Sorry.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our beloved elder Campbell has his eyes playing tricks on him again
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this points out the importance of proper indentation to the OP. If it is not correctly indented, it's wrong; despite whether it works or not.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@bairava surya once a method declares that it throws then the method must be called within a guarded region or the method calling it must also declare that it throws...
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:Our beloved elder Campbell has his eyes playing tricks on him again
What are eyes.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:But this points out the importance of proper indentation to the OP. If it is not correctly indented, it's wrong; despite whether it works or not.


Totally agree... As formatting errors has proven to introduce multimillion dollar bugs
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Rico Felix wrote:Our beloved elder Campbell has his eyes playing tricks on him again
What are eyes.


I'm assuming the plural to eye which is an organ that reacts to light.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:But this points out the importance of proper indentation to the OP. If it is not correctly indented, it's wrong; despite whether it works or not.

And if it doesn't put the opening curly bracket on a line by itself, its indentation is wrong, whether it's correctly indented or not.

(Oh, my... did I say that out loud? )
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:And if it doesn't put the opening curly bracket on a line by itself, its indentation is wrong, whether it's correctly indented or not.
(Oh, my... did I say that out loud? )


All Allman patriots pledge your allegiance...
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:All Allman patriots pledge your allegiance...


Your loyalties will not go unrewarded.

Since this is actually a valid point, and to assist the OP (and the rest of us), here's his code in Allman-proper style:



BTW, the import isn't needed.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Contrast to:


Cast your votes...
[ ] K&R
[ ] Allman
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:


an empty catch block is wrong regardless of brace placement OR indentation.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I blame Stevens Miller for guiding me down that path but I'll accept the punishment for knowing better ...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only quoted yours as it was at the bottom, and the easiest.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, don't blame me or Rico. We're just reformatting someone else's code.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not blaming anybody since I can't see it anyway
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm calling time on the curly brace placement flame war. We're heading way off topic here.

I have a question for the OP:
bairava surya wrote:In above even though exception is handled in catch block still it shows an error

What error do you see? You haven't told us what happens when you run this code.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:You haven't told us what happens when you run this code.

He can't really do that, Tim. He has a compile time error. at this line:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!