home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!fmrco!fmrco!asherman
- From: asherman@laser.fmrco.com (Aaron Sherman)
- Subject: Exception handling (was: Re: or puzzlement)
- In-Reply-To: flee@cs.psu.edu's message of Mon, 27 Jul 1992 22:42:24 GMT
- Message-ID: <ASHERMAN.92Jul29102950@laser.fmrco.com>
- Sender: news@fmrco.uucp
- Reply-To: asherman@fmrco.COM
- Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
- References: <BrtMFu.D0L@unx.sas.com> <1992Jul23.191243.9731@netlabs.com>
- <Bs2HMz.Gqp@cs.psu.edu>
- Date: Wed, 29 Jul 1992 15:29:50 GMT
- Lines: 49
-
-
- One thing that I was doing, when I was trying to write a perl
- interface to the X protocol, involved an exception handling library
- that would handle the concept of having multiple errors occur in one
- call.
-
- What I came up with was something that looked like:
-
- &lib_error_procname($0);
-
- unless (&openfoo)
- {
- &lib_error_die('opening output file');
- }
-
- sub openfoo
- {
- # This function will return false if BOTH opens fail.
- unless(open(FOO,"foo"))
- {
- # Log that the open failed, but do not return false.
- &lib_error('OPENFAIL',"foo: $!");
- # If this open fails, then the routine fails.
- open(FOO,'bar') || &lib_error('OPENFAIL',"bar: $!");
- }
- }
-
- If this failed, then you would get:
-
- testprog: Error opening output file:
-
- Open call failed: foo: No such file or directory.
- Open call failed: bar: No such file or directory.
-
- This has many personal quirks (like wanting a "list of known errors"
- ala perror), but served the purpose of having subroutines that didn't
- need to know why they were being called, or print out errors, and
- still returned a list of problems.
-
- BTW: one important feature is that &lib_error ALWAYS returns false.
-
-
- -AJS
-
- --
- --------
- Disclaimer: I am solely responsible for the content of this message.
- The views expressed here may not be the views of I-Kinetics, Fidelity,
- any of the Fidelity-owned corporations or my mother.
-