473,404 Members | 2,178 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,404 software developers and data experts.

Exception problems between languages

I have a new problem with Exceptions: I need to manage the exception but I
don't have an error code to compare with, just messages. I can check a
message to see if it has "timeout" then instruct my code to try again later,
however, if the message is "not found" then I want to rethrow the exception
or log it. This can work fine, but the real problem comes when I install
this on a system that produces exception strings in another language like
Chinese, then I can no longer catch and manage using the message string.
Anyone, know how to handle this?

Thanks in advance,
Donald Adams
Jul 21 '05 #1
2 1557
You should absolutely, positively, *not* use the error message as a means of
determining what type of exception has occurred. These messages can easily
change, either between revisions, between locales, when new layers are added
between your code and the underlying source of the exception, or when a
subsystem component gets changed that performs the same function but uses a
slightly different error message. There is no standard that applies to error
messages, certainly not one that is enforced by the runtime, thus there is
no way you can be sure that your app wont break. This sort of fragility
should be avoided at all costs.

Instead, you should use the exception type itself to determine how to handle
the error. You should catch the most specific exception type and handle the
error appropriately. For example, FileNotFoundException is thrown when an
attempt to access a file on disk fails. Catch this and deal with it rather
then look at the message to determine if the access failed.

If the exception is thrown by a COM object or an external Win32 method then
this becomes harder because you will only get a single exception type
(either COMException or SEHException). You can use the ErrorCode property to
retrieve the specific HRESULT that was returned by the faulting method.

If there really is no programmatic means of determining the cause of the
exception other then the message then I would approach the supplier of the
component and ask them to supply specific exception types (or HRESULTS for
Win32 methods) for each error type - good component practice should dictate
this anyway. If this cannot be done then you are on your own.

Dave L
"Donald Adams" <BD******@hotmail.com> wrote in message
news:OF*************@tk2msftngp13.phx.gbl...
I have a new problem with Exceptions: I need to manage the exception but I
don't have an error code to compare with, just messages. I can check a
message to see if it has "timeout" then instruct my code to try again later, however, if the message is "not found" then I want to rethrow the exception or log it. This can work fine, but the real problem comes when I install
this on a system that produces exception strings in another language like
Chinese, then I can no longer catch and manage using the message string.
Anyone, know how to handle this?

Thanks in advance,
Donald Adams

Jul 21 '05 #2
You should absolutely, positively, *not* use the error message as a means of
determining what type of exception has occurred. These messages can easily
change, either between revisions, between locales, when new layers are added
between your code and the underlying source of the exception, or when a
subsystem component gets changed that performs the same function but uses a
slightly different error message. There is no standard that applies to error
messages, certainly not one that is enforced by the runtime, thus there is
no way you can be sure that your app wont break. This sort of fragility
should be avoided at all costs.

Instead, you should use the exception type itself to determine how to handle
the error. You should catch the most specific exception type and handle the
error appropriately. For example, FileNotFoundException is thrown when an
attempt to access a file on disk fails. Catch this and deal with it rather
then look at the message to determine if the access failed.

If the exception is thrown by a COM object or an external Win32 method then
this becomes harder because you will only get a single exception type
(either COMException or SEHException). You can use the ErrorCode property to
retrieve the specific HRESULT that was returned by the faulting method.

If there really is no programmatic means of determining the cause of the
exception other then the message then I would approach the supplier of the
component and ask them to supply specific exception types (or HRESULTS for
Win32 methods) for each error type - good component practice should dictate
this anyway. If this cannot be done then you are on your own.

Dave L
"Donald Adams" <BD******@hotmail.com> wrote in message
news:OF*************@tk2msftngp13.phx.gbl...
I have a new problem with Exceptions: I need to manage the exception but I
don't have an error code to compare with, just messages. I can check a
message to see if it has "timeout" then instruct my code to try again later, however, if the message is "not found" then I want to rethrow the exception or log it. This can work fine, but the real problem comes when I install
this on a system that produces exception strings in another language like
Chinese, then I can no longer catch and manage using the message string.
Anyone, know how to handle this?

Thanks in advance,
Donald Adams

Jul 21 '05 #3

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

Similar topics

11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
19
by: KKramsch | last post by:
One of the features from other languages that I miss most in C is trappable exceptions. More specifically, I think it's great to be able to demarcate a whole block of code where several exceptions...
5
by: Dan Smith | last post by:
When I try to create a new C# Web Reference in Visual Studio 2003, I get an error message "The proxy settings on this computer are not configured correctly for web discovery. ..." This web...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
20
by: Bonj | last post by:
Hello. Does anybody know if there is a difference between the way C# calls a COM object, and the way C++ calls a COM object? And is there anyway to make the latter emulate the former? I have a...
2
by: Donald Adams | last post by:
I have a new problem with Exceptions: I need to manage the exception but I don't have an error code to compare with, just messages. I can check a message to see if it has "timeout" then instruct...
4
by: Sharon | last post by:
Hi, I'm using the remoting, and I have a remoting object that has a public event that other processes should register to it. But when the client process is registering to the remote event, it...
7
by: Søren Dreijer | last post by:
Hi, I have a mixed C#, managed C++ and unmanaged C++ project. The managed class calls a method which exists in an unmanaged singleton class. During the entire lifetime of the application, this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.