Is the glass half empty or half full?
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Why would I expect an error? I'd just pop up a message saying "The luser obviously screwed up."
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
The glass is twice the size needed. I've used such constructs in the past, but meanwhile mostly avoid catching all exceptions and just returning true/false because in order to fix the problem you usually need to know what the exception was. Otherwise you can only say "something went wrong", without any further information about the where and why.
Regards, mav -- Black holes are the places where God divided by 0...
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
exit(0);
- S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Depends on what I am doing: is success to be expected, or failure?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
I don't look at the success like a boolean! There is a Mystery in this word! if you believe in your self its always True! but if you get doubt in your self just a little or disappointed , I things get change!
-
I don't look at the success like a boolean! There is a Mystery in this word! if you believe in your self its always True! but if you get doubt in your self just a little or disappointed , I things get change!
Oh Boy! Have you got a major disappointment coming... Nothing in life works all the time. And if you aren't ready for when it doesn't, then it will hit you like a tonne of bricks.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
The glass is twice the size needed. I've used such constructs in the past, but meanwhile mostly avoid catching all exceptions and just returning true/false because in order to fix the problem you usually need to know what the exception was. Otherwise you can only say "something went wrong", without any further information about the where and why.
Regards, mav -- Black holes are the places where God divided by 0...
mav.northwind wrote:
Otherwise you can only say "something went wrong", without any further information about the where and why.
Yes, indeed. I was responsible for keeping such a horrible application alive. When an exception occured, it was either swept under the rug in an empty catch block or it sent off a mail to me with 'An error has just occured'. Sometimes I got hundreds of those mails, all with that braindead message. How hard can it be to think of includng the message and perhaps the stack trace in that mail? For this and many other horrors this man has commited, I would just love to see him tarred, feathered, first thrown out of the guild and then thrown out of the town. :)
At least artificial intelligence already is superior to natural stupidity
-
Oh Boy! Have you got a major disappointment coming... Nothing in life works all the time. And if you aren't ready for when it doesn't, then it will hit you like a tonne of bricks.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
but the important part of that is: "some times life hit your head with a break , don't lose faith" steve jobs, stanford university!
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
It's always full[^] In answer to your question:
try
{
// ...
return true;
}
catch (Exception ex)
{
// ...
return false;
}Assuming you don't return anywhere else. I don't agree with an idea that a method must have only one point of exit, and have never found code less readable as a result with modern IDEs. In your example I have to get to the bottom of the method to find out what the
boolean
does, and you have to worry about defensive coding. Obviously, other people will have different views on this.Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^] -
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.
Will Rogers never met me.
-
I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.
Will Rogers never met me.
...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...
Will Rogers never met me.
-
I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...
Will Rogers never met me.
It's worth taunting them though - A "NO! For Gods sake, NO! STOP!" button is a good idea, provided it is permanently disabled.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Typically I use the error point of view... I prefer to stop the program / action if something unhandled has happened. Of course I program machines and it can be dangerous to move something in an unhandled way...
[www.tamautomation.com] Robots, CNC and PLC machines for grinding and polishing.
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
It depends on the situation. Each is better suited to different scenarios so you shouldn't code it one way all the time.
-
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
:thumbsup: This is the very idea that I teach my students in any of the programming courses I teach.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.
A guide to posting questions on CodeProject[^]
Dave KreskowiakDave Kreskowiak wrote:
not enumerating badness missing a test or piece that wasn't in the design
Yes. It does make testing easier, and gives more assurance that proof of concept that the code is well designed.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP