* error handling in DCE-based applications
@ 1994-10-25 9:03 nader nayeri
1994-10-25 17:21 ` Mustafizur Rahman
1994-10-27 16:26 ` Rich Salz
0 siblings, 2 replies; 3+ messages in thread
From: nader nayeri @ 1994-10-25 9:03 UTC (permalink / raw)
Together with HP DCE a sample application is shipped called 'phone_db'. The
application contains the following code for error handling:
unsigned32 pdb_print_error(unsigned32 err_num, char *prefix)
{
int _ignore;
dce_error_string_t dce_err_string; /* text describing error code */
char err_buf[dce_c_error_string_len + 80];
char * cp = NULL;
sprintf(err_buf, "%s: ", prefix);
if (err_num > 512) {
/*
* Then the error must be a DCE error.
*/
dce_error_inq_text(err_num, dce_err_string, &_ignore);
cp = (char *)dce_err_string;
} else if (err_num >= 256) {
cp = pdb_app_error_string(err_num);
} else if (err_num > 0) {
/*
* This is a system errno, not a DCE error.
*/
cp = strerror(err_num);
}
if (cp != NULL)
strcat(err_buf, cp);
fprintf(stderr, "%s\n", err_buf);
if (tr_handle != NULL)
tr_printmsg(tr_handle, NULL, err_buf);
return err_num;
}
This seems to me to be an elegant way to handle errors in an
uniform way. But would this solution also work on other UNIX platforms (SUN)?
I mean, how can I be sure that the numeric constants used in the code
(512, 256) are not (or are they) platform specific? Is there any way to
rewrite the code in a more portable manner?
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: error handling in DCE-based applications
1994-10-25 9:03 error handling in DCE-based applications nader nayeri
@ 1994-10-25 17:21 ` Mustafizur Rahman
1994-10-27 16:26 ` Rich Salz
1 sibling, 0 replies; 3+ messages in thread
From: Mustafizur Rahman @ 1994-10-25 17:21 UTC (permalink / raw)
In article <NAYERI.94Oct25100302@slbh13.bln.sel.alcatel.de>, nayeri@slbh13.bln.sel.alcatel.de (nader nayeri) writes:
|>Newsgroups: comp.unix.osf.misc
|>Together with HP DCE a sample application is shipped called 'phone_db'. The
|>application contains the following code for error handling:
|>
|>unsigned32 pdb_print_error(unsigned32 err_num, char *prefix)
|>{
|> int _ignore;
|> dce_error_string_t dce_err_string; /* text describing error code */
|> char err_buf[dce_c_error_string_len + 80];
|> char * cp = NULL;
|>
|> sprintf(err_buf, "%s: ", prefix);
|>
|> if (err_num > 512) {
|> /*
|> * Then the error must be a DCE error.
|> */
|> dce_error_inq_text(err_num, dce_err_string, &_ignore);
|> cp = (char *)dce_err_string;
|> } else if (err_num >= 256) {
|> cp = pdb_app_error_string(err_num);
|>
|> } else if (err_num > 0) {
|> /*
|> * This is a system errno, not a DCE error.
|> */
|> cp = strerror(err_num);
|> }
|>
|> if (cp != NULL)
|> strcat(err_buf, cp);
|>
|> fprintf(stderr, "%s\n", err_buf);
|> if (tr_handle != NULL)
|> tr_printmsg(tr_handle, NULL, err_buf);
|>
|> return err_num;
|>}
|>
|>This seems to me to be an elegant way to handle errors in an
|>uniform way. But would this solution also work on other UNIX platforms (SUN)?
|>I mean, how can I be sure that the numeric constants used in the code
|>(512, 256) are not (or are they) platform specific? Is there any way to
|>rewrite the code in a more portable manner?
We have a similar solution which is used by all our applications.
Using message catalogs, we define all the common OS and some of
the more common system errors (e.g. NFS errors) combined with
local application errors in conjunction with end markers. Applications
call library routines which then retrieves the error string or prints
it to stderr regardless of whether it is an OS, application or DCE
error code.
We do have to check and make sure that the OS defined error codes
match the ones in our message catalog when we port it to a new
platform but this is a one time process *per* platform. For most
parts, the system errors seem consistent across platforms. Using
this simple library helped trmendeously in dealing with errors
in applications.
- Mustie
--
Mustafizur Rahman Internet: rahman@pilgrim.umass.edu
Project Pilgrim rahman@umvlsi.ecs.umass.edu
Department of Computer Science Phone: (413) 545-4701
A143B Lederle Graduate Research Center Fax: (413) 545-1249
University of Massachusetts
Amherst, MA 01003
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: error handling in DCE-based applications
1994-10-25 9:03 error handling in DCE-based applications nader nayeri
1994-10-25 17:21 ` Mustafizur Rahman
@ 1994-10-27 16:26 ` Rich Salz
1 sibling, 0 replies; 3+ messages in thread
From: Rich Salz @ 1994-10-27 16:26 UTC (permalink / raw)
In <NAYERI.94Oct25100302@slbh13.bln.sel.alcatel.de> nayeri@bln.sel.alcatel.de writes:
>Together with HP DCE a sample application is shipped called 'phone_db'. The
>application contains the following code for error handling:
...
>This seems to me to be an elegant way to handle errors in an
>uniform way.
No, it's a hack. Trying to handle both DCE status codes and native
system errors (such as errno) is almost guaranteed to not be portable.
However, the following might help:
- Try always calling dce_error_inq_text; if the status param is -1
then it's either not DCE error code or the required message catalog
isn't available.
- If "random_status >>24" is 1 or 2, then it's in the space that DCE
reserves for itself and DFS.
Note that these get you more portable, not truly portable.
Mixing errno-like things and DCE status codes is a mistake.
/r$
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1994-10-27 16:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-10-25 9:03 error handling in DCE-based applications nader nayeri
1994-10-25 17:21 ` Mustafizur Rahman
1994-10-27 16:26 ` Rich Salz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox