We’re rewarding the question askers & reputations are being recalculated! Read more.
6 Improved formatting (shortened long sentences)
source | link

The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

BuHoweverHowever, the code didn't catch anything. Similarly one could think in Java it would be as follows:

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

BuHowever, the code didn't catch anything. Similarly one could think in Java it would be as follows:

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

However, the code didn't catch anything. Similarly one could think in Java it would be as follows:

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

5 Improved formatting (shortened long sentences)
source | link

The classical way to program is with try / ... catch but when. When is it appropriate to use try without catch? 

In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

But weBuHowever, the code didn't catch anything. Similarly one could think in Java it would be as follows:

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types, etc. But ifIf this is good practice, when is it good practice? OrAlternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about andit as it could be a syntax error for Java but. I checked that the Python surely compiles.)

A related problem I've run into is thatthis: I continue writing the function  / method andmethod, at the end Iof which it must return something and I'm. However, it may be in a place which should not be reached and it must be a return point so. So, even if I handle the exceptions above, I'm still returning nullNULL or an empty string at some point in the code which should not be reached, often the end of the method  / functionfunction. I've always managed to restructure tothe code so that I don'tit doesn't have to return nullNULL, since that absolutely appears to look like less than good practice.

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

But we didn't catch anything. Similarly one could think in Java it would be

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types etc. But if this is good practice, when is it good practice? Or reasons why this is not good practice or not legal (I didn't compile the source I'm asking about and it could be a syntax error for Java but I checked that the Python surely compiles.)

A related problem I've run into is that I continue writing the function  / method and at the end I must return something and I'm in a place which should not be reached and it must be a return point so even if I handle the exceptions above I'm still returning null or an empty string at some point in the code which should not be reached, often the end of the method  / function. I've always managed to restructure to code so that I don't have to return null since that absolutely appears to look like less than good practice.

The classical way to program is with try ... catch. When is it appropriate to use try without catch? 

In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

BuHowever, the code didn't catch anything. Similarly one could think in Java it would be as follows:

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

    Question Protected by gnat
    Notice removed Reward existing answer by Niklas Rosencrantz
    Bounty Ended with ChrisF's answer chosen by Niklas Rosencrantz
    Notice added Reward existing answer by Niklas Rosencrantz
    Bounty Started worth 200 reputation by Niklas Rosencrantz
    Notice removed Reward existing answer by Niklas Rosencrantz
    Bounty Ended with ChrisF's answer chosen by Niklas Rosencrantz
    Tweeted twitter.com/#!/StackProgrammer/status/531818629981954049
    Notice added Reward existing answer by Niklas Rosencrantz
    Bounty Started worth 100 reputation by Niklas Rosencrantz
4 Clarified title; fixed typo; formatting edit simply to exceed the 6-char minimum
source | link

When to Why use try … finally without a catch and finally insteadclause?

The classical way to program is with trytry / catchcatch but when is it appropriate to use trytry without catchcatch? In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do somehingsomething unconditional

But we didn't catchcatch anything. Similarly one could think in Java it would be

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types etc. But if this is good practice, when is it good practice? Or reasons why this is not good practice or not legal (I didn't compile the source I'm asking about and it could be a syntax error for Java but I checked that the Python surely compiles.)

A related problem I've run into is that I continue writewriting the function / method and at the end I must return something and I'm in a place which should not be reached and it must be a return point so even if I handle the exceptions above I'm still returning null or an empty string at some point in the code which should not be reached, often the end of the method / function. I've always managed to restructure to code so that I don't have to return null since that absolutely appears to look like less than good practice.

When to use try without catch and finally instead?

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do somehing unconditional

But we didn't catch anything. Similarly one could think in Java it would be

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types etc. But if this is good practice, when is it good practice? Or reasons why this is not good practice or not legal (I didn't compile the source I'm asking about and it could be a syntax error for Java but I checked that the Python surely compiles.)

A related problem I've run into is that I continue write the function / method and at the end I must return something and I'm in a place which should not be reached and it must be a return point so even if I handle the exceptions above I'm still returning null or an empty string at some point in the code which should not be reached, often the end of the method / function. I've always managed to restructure to code so that I don't have to return null since that absolutely appears to look like less than good practice.

Why use try … finally without a catch clause?

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense:

try:
  #do work
finally:
  #do something unconditional

But we didn't catch anything. Similarly one could think in Java it would be

try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}

It looks good and suddenly I don't have to worry about exception types etc. But if this is good practice, when is it good practice? Or reasons why this is not good practice or not legal (I didn't compile the source I'm asking about and it could be a syntax error for Java but I checked that the Python surely compiles.)

A related problem I've run into is that I continue writing the function / method and at the end I must return something and I'm in a place which should not be reached and it must be a return point so even if I handle the exceptions above I'm still returning null or an empty string at some point in the code which should not be reached, often the end of the method / function. I've always managed to restructure to code so that I don't have to return null since that absolutely appears to look like less than good practice.

3 corrected spelling
source | link
2 formatting
source | link
1
source | link