DarVar
DarVar

Reputation: 18124

Netty SimpleChannelHandler methods throw base Exception type

The handlers I implemented override SimpleChannelHandler messageReceived, channelConnected and exceptionCaught methods.

Throwing a base Exception type means PMD complains "Signature Declare Throws Exception".

What is the best way to handle Netty exceptions so as not the throw base Exception types?

My guess is to remove the "throws Exception" from all my handlers. Then any exception that occurs will eventually get propagated up to the exceptionCaught() method in the last upstream/downstream Handler in the pipeline. Is this a correct assumption?

Upvotes: 1

Views: 391

Answers (1)

rfeak
rfeak

Reputation: 8204

Although I happen to agree with PMD on this, the object model of Netty is different and uses a raw Exception. If you are programming against the Netty API, it would probably be better (for consistency, readability, etc.) to follow their model.

Don't let a static analysis tool be the deciding factor on your code. Sometimes there are exceptions (nice pun, not intended)

Upvotes: 1

Related Questions