This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need exception  RSS feed

 
mark smith
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i try to call the method: extractPdf()




i got a error:
unreported exception java.io.IOException must be caught or declared to be thrown

any idea?

thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mark smith:
...i try to call the method: extractPdf()...

i got a error:
unreported exception java.io.IOException must be caught or declared to be thrown...

The method extractPdf declares that it might throw an IOException. Therefore, when you call this method, your calling line might throw an IOException. The line of code indicated in your error message is probably something like...

pdf2txt.extractPdf();

It looks like you're already catching any IOException within the extractPdf method, so I don't think that method needs to declare a possible exception. If you remove that declaration, then your calling line should be okay.
[ May 27, 2006: Message edited by: marc weber ]
 
mark smith
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

The method extractPdf declares that it might throw an IOException. Therefore, when you call this method, your calling line might throw an IOException. The line of code indicated in your error message is probably something like...

pdf2txt.extractPdf();

It looks like you're already catching any IOException within the extractPdf method, so I don't think that method needs to declare a possible exception. If you remove that declaration, then your calling line should be okay.

[ May 27, 2006: Message edited by: marc weber ]


true that work...... but i need to add another try catch in the finnaly for the document.close....
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i need to add another try catch in the finnaly for the document.close....


This is a far better way to close a file reading object. You can use the same combination of try blocks for any other analogous object.

Yes, you have a try-finally inside the first try.

CR

. . . And because I set up input as a local variable in that example, you have to do something with it in the method, or return it, otherwise it will vanish along with whatever you read from the file.

[ May 28, 2006: Message edited by: Campbell Ritchie ]
[ May 29, 2006: Message edited by: Campbell Ritchie ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!