Comment On Because New() Fails Way Too Much

First and foremost, thanks for the WTF submissions! Please keep 'em coming. They don't have to be code snippets or diagrams, just something technical-related that made you say or think What the F--! And now that I think about it, I'd love to see some crazy Boss Emails and Memos. I had a trove of them saved from the last company I was at, but lost them all. So let's see yours! Just use the Contact Form, and feel free to include a website to link back to. [expand full text]
« PrevPage 1Next »

re: Because New() Fails Way Too Much

2004-05-26 16:21 • by Frans Bouma
But... constructors do fail sometimes. So it's not that weird to test if the constructor succeeded, especially if the constructor does things which can fail (open a connection or something).

(But perhaps my lack of VB.NET skillz stops me from seeing the weirdness).

I'm more concerned about throwing an exception without a description

re: Because New() Fails Way Too Much

2004-05-26 16:27 • by Alex Papadimoulis
Frans makes an good point. But, when a constructor fails, it will throw exception, not refuse to make an instance. Proper code:

try { myInstance = new myClass(); }
catch { ... }

re: Because New() Fails Way Too Much

2004-05-26 16:39 • by Jerry Pisk
I think there's an "On Error Resume Next" statement at the top if the file... In that case the logic would make sense in the context it's used in.

re: Because New() Fails Way Too Much

2004-05-26 16:43 • by John Bush
The error handling is inconsistent, too.

If you pass the function an intNewsId of less than one, it returns the string 'Invalid ID'.

But if New() fails, it throws an exception with no description.

WTF?

re: Because New() Fails Way Too Much

2004-05-26 22:59 • by Bobby V.
I'm a C# programmer, not a VB.NET programmer, but if there is an "On Error Resume Next" statement at the top, wouldn't the Exception they thrown be suppressed by the "On Error Resume Next"? Personally, any coder that uses "On Error..." should be shot. I've debugged way too much poorly written VB6 and ASP code what hard to identify problems due to the "On Error...".

Alex is correct in the way to code this.

re: Because New() Fails Way Too Much

2004-05-27 13:25 • by Vijay
Ok. I might be totally off the mark on his but just a thought.

hmm now wait a minute... If i remember right, at the point where the constructor logic is executed, the object must have already been allocated and the initialisation logic only needs to be done in the constructor. Now if some one is stupid enough to probably throw an exception in the constructor, then that will definitely result in a null object allocation ( not sure here too .. ) This exception might be thrown just because some resource could not be initialized or whatsoever but then the object memory allocation would not be null even then !

But like you said, if there is a "On Error Resume Next" statement at the top, then all i can see is that exception will happen at the first line, but it will continue, and from then on, everytime the code tries to access objNews, it should keep throwing an exception but code will keep ignoring it ..

I'd definitely say WTF aloud for this one ;-)
Any comments ?

re: Because New() Fails Way Too Much

2004-05-27 14:19 • by Frans Bouma
"But, when a constructor fails, it will throw exception, not refuse to make an instance. Proper code: "
You're right, I forgot about that :) It's so obvious that I totally overlooked that completely :D

re: Because New() Fails Way Too Much

2004-05-27 14:55 • by Jake Vinson
Wow, John Bush, the singer of Anthrax reads your blog. That kicks ass!

re: Because New() Fails Way Too Much

2004-07-07 13:49 • by Delphi7
What happens if the exception constructor fails
(New Exception)

Re: re: Because New() Fails Way Too Much

2006-11-17 16:46 • by Bill Moore
102557 in reply to 22231

You nailed that one

« PrevPage 1Next »

Add Comment