exception - What's the purpose of the 'throws' statement in Java? -


i'm learning java, seems in end of methods in beginning of call stack have declarations 'throws exception'. what's thing statement i'm missing makes useful?

one more example. after writing code, decided refactor 1 of classes bit, using classes other java libraries; result, not half of methods of class gained 5 exceptions in declarations, half of other code, – until decided i'd better write 'throws exception' , don't care about. may use exceptions wrong?

important edit

my question wasn't statement – pretty obvious documentation. wondering why language designers decided make statement necessary.

although other answers right-on, think missed purpose in way asking it.

the throws statement how create exception stack trace. there isn't magic in java--it's not underlying system mystery creates exception, "throw" statement, , therefore last few entries in stack trace throw.

it's not last 1 because in many cases exception handling consists of this:

try {      might cause exception catch(expectedexception e) {      throw new differetnexception(e); } 

this lets change type of exception or add better textual description or handle of exceptions while re-throwing others.

because of last few levels (and maybe in-between) caused "throw" statement.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -