Forum Stats

  • 3,727,847 Users
  • 2,245,474 Discussions
  • 7,853,067 Comments

Discussions

Checked assignments anyone?

User_0CXEZ
User_0CXEZ Member Posts: 237 Blue Ribbon

Hello.

For a while now I have been disliking the way I have to declare a variable outside a try block whenever I assign to the given variable anything returned from a method that throws an exception I may want to handle from the code in which the assignment is made.

There isn't much facility to provide code here, so I'll just give the example of what I'd like to do as a one-liner:

Type variable=try receiver.method();

The catch block would be provided as usual. Indeed, one could assign more than one variable before coding a catch block, and this would help keep code concise. Additionally, when using the var keyword, one wouldn't have to quote types that were long or had extensive parameter lists.

Who likes this idea? Who doesn't? Why wouldn't you?

Sign In or Register to comment.