in reply to Re: Re: Newbies TCP Networking
in thread Newbies TCP Networking
Now, in your program you will call OpenSomething(), which might actually return nothing. You forget to check if you got anything back, so later on when you call CloseSomething() you get an error. The error, it would seem, originates in CloseSomething().sub OpenSomething { my ($param) = @_; # What kind of an idiot would forget the foo parameter! return unless (defined $param->{foo}); my $thing = new Object ($param->{foo}, $param->{zoo}); $thing->open($param->{foozoo}); return $thing; } sub CloseSomething { my ($thing) = @_; $thing->close(); }
Now what you have done, effectively, is swept all these errors under the carpet. They don't manifest, and they don't cause "errors" in the visible sense, but there may be problems with the way your program runs that doesn't make any sense.sub CloseSomething { my ($thing) = @_; # Maybe they forgot to pass the parameter? return unless (defined $thing); $thing->close(); }
Using die in this capacity is similar to the ASSERT() macro used in C programming which will completely halt the program if something is seriously out of line.sub OpenSomething { my ($param) = @_; # What kind of an idiot would forget the foo parameter! die "No 'foo' param passed to OpenSomething()" unless (defined $ +param->{foo}); my $thing = new Object ($param->{foo}, $param->{zoo}); $thing->open($param->{foozoo}); return $thing; } sub CloseSomething { my ($thing) = @_; die "Cannot CloseSomething() with undefined parameter" unless (d +efined $thing); $thing->close(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^3: Newbies TCP Networking
by otijim (Acolyte) on Jul 11, 2001 at 23:12 UTC |