473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Exception errorcodes?

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
Nov 15 '05 #1
6 7093
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
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

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #3
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 as**@asdf.com 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" <st*****@mvps.org> wrote in message
news:Om*************@TK2MSFTNGP10.phx.gbl...
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

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


Nov 15 '05 #4
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.

"William Stacey" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #5

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" <st*****@mvps.org>
| 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: <#x**************@TK2MSFTNGP10.phx.gbl>
| 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!TK2MSFTN GP10.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
|
|
|

Nov 15 '05 #6
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

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:ZH**************@cpmsftngxa06.phx.gbl...

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" <st*****@mvps.org>
| 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: <#x**************@TK2MSFTNGP10.phx.gbl>
| 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!TK2MSFTN GP10.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
|
|
|

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very...
1
by: Old Wolf | last post by:
1. What is the difference between #include <stdexcept> and #include <exception> ? 2. Is there a list somewhere of what each standard exception is used for? either to throw them, or throw...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
5
by: PCC | last post by:
I am using the Exception Managment Application Block on Windows Server 2003 Enterprise and .NET v1.1. If I use the block with an ASP.NET web wervice or in a web application I get the following...
2
by: Alex | last post by:
Hi. What would happen if an exception occurs inside a Finally block and at the same time inside the try another exception was thrown without been handled by any catch? Alejandro.
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
3
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let...
2
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.