Exception errorcodes?

  • Thread starter Thread starter William Stacey
  • Start date Start date
W

William Stacey

Wouldn't it be better if you could throw one of the prebuilt exceptions,
such as ApplicationException or ArgumentNullException, and also supply a
numeric errorcode with it. Then the users can check that instead of the
text message. I know you can create your own exceptions, but this would fit
most situations without the need to create new classes. Or maybe you can
already?
TIA
 
William,
Then the users can check that instead of the text message.

Who's the user? The application's end users? I don't think you should
display exception messages to them anyway. Exception messages tend to
be way to technical for most end users. Displaying an error number
would be even worse.



Mattias
 
The "user" is the user of the library (i.e. a programmer using the library
who may check exception code and do something different.)
--wjs
 
One nice way I've seen is that Exception messages are
some type of resource string like "RETRIEVE_PROFILE"
or something and the custom exception also takes another
parameter which is an error code.

The full exception details are written to a log
(EventLog, database, file, etc) with that error code
and then a polite message with that error code is
returned to the user.

RETRIEVE_PROFILE is a resource identifier which loads
a localized string. The end user sees something like:

"Error retrieving your user profile information.
Please contact technical support at (e-mail address removed) and
reference error code 12912-129812098"

That error code is unique to that error and so the
tech support guy can check the log and see the
full exception details and anything else you logged
immediately before and after that and provide
some sort of useful troubleshooting.

-c


William Stacey said:
The "user" is the user of the library (i.e. a programmer using the library
who may check exception code and do something different.)
--wjs
 
i perosnally dont think you should branch your exception handling on the
contents of a string or number. handle your exceptions as a catch
(YourException ex). it might seem more effort to create your own classes,
but its not much, and your code will be overall more consistent and
maintainable...

r.
 
Hi William,

I think the exception message is more readable than numeric.
In Windows, the getlasterror() function will get the error number, but it
isn't convinient,
so FormatMessage() function is provided to translate the error number into
readable message.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "William Stacey" <[email protected]>
| Subject: Exception errorcodes?
| Date: Fri, 15 Aug 2003 11:08:32 -0400
| Lines: 12
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 66.188.59.114.bay.mi.chartermi.net 66.188.59.114
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:176684
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Wouldn't it be better if you could throw one of the prebuilt exceptions,
| such as ApplicationException or ArgumentNullException, and also supply a
| numeric errorcode with it. Then the users can check that instead of the
| text message. I know you can create your own exceptions, but this would
fit
| most situations without the need to create new classes. Or maybe you can
| already?
| TIA
|
| --
| William
|
|
|
 
Agreed mostly. It is more readable to humans, but not to calling code.
Think about all the code that we all have written to check ftp error
messages or batch file error messages. The codes usually changed a lot less
then the text of an error message which requires a rewrite of your code to
correctly process error returns. I never felt confortable relying on error
text to process an error - numeric codes seem more....well better suited to
that job imo.
--wjs
 
Back
Top