Assume a method getBar
which throws a checked exception. It takes an instance of Foo
. Foo is never used anywhere else in code and it does not throw exception and its only job is to be a parameter to getBar
. Should foo
be declared and initialized inside or outside a try ? Extending the question - should code inside try
be minimal (as my second option) or wrap a block of similar related lines of code (as my first option) ?
try {
Foo foo = new Foo();
var result = SomeConnection.getBar(foo);
return result == foo.RESULT;
} catch ( .. ) {...}
OR
Foo foo = new Foo();
try {
SomeConnection.getBar(foo);
return result == foo.RESULT;
} catch ( .. ) {...}