473,467 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to change to error message

ad

I use try..catch(exception e) to catch excption and show to error(e.Message)
to user.
But the error is some difficult for user to understand.
How can I change the e.Message to some custom message.
Nov 17 '05 #1
3 1576
ad,

You catch objects of type Exception, which means you handle all exceptions
in the same place. My suggestion is to filter down the exception that you
expect to be thrown by type. then in the event handlers instead
error(e.Message) you can emit most friently message.

try
{
}
catch(ExceptionType1 e1)
{
error("message1");
}
catch(ExceptionType2 e1)
{
error("message2");
}
catch(ExceptionType3 e1)
{
error("message3");
}
catch(Exception e)
{
// for unexpected exceptions you can show the original message or some
message in the line of the "unexpected error"
error(e.Message);
}

You have to always start from the more specific to the common exception
types. If you put catch(Exception e) as a first exception block it will
catch all the exception and the execution will never enter the other blocks.
HTH
Stoitcho Goutsev (100) [C# MVP]
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...

I use try..catch(exception e) to catch excption and show to
error(e.Message)
to user.
But the error is some difficult for user to understand.
How can I change the e.Message to some custom message.

Nov 17 '05 #2
You can´t change the Message property of an Exception, but you can throw a
new exception with the text that you want passing the caught exception as
inner exception:

....
catch Exception ex
{
throw new ApplicationException("my text", ex);
}

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"ad" <ad@wfes.tcc.edu.tw> escribió en el mensaje
news:%2***************@TK2MSFTNGP15.phx.gbl...

I use try..catch(exception e) to catch excption and show to
error(e.Message)
to user.
But the error is some difficult for user to understand.
How can I change the e.Message to some custom message.

Nov 17 '05 #3
ad,

I would recommend that in the case of exceptions, you do not try and
show a friendly message at all. Rather, you should be checking the
conditions in your code that you can anticipate, and then displaying error
information when those conditions are not met.

Using exceptions as a way of handling logic errors is not the best of
approaches. For example, if you are trying to open a file, you should check
to see if the file exists first before trying to open it, instead of relying
on a FileNotFoundException being thrown.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...

I use try..catch(exception e) to catch excption and show to
error(e.Message)
to user.
But the error is some difficult for user to understand.
How can I change the e.Message to some custom message.

Nov 17 '05 #4

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

Similar topics

4
by: J.C. Flores | last post by:
Hello all, First of all, I must state that I'm new to SQL Server, but have been a long-time software guy for quite some time. Please excuse the potential simplicity of the solution to my...
10
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
14
by: Mr.KisS | last post by:
Hi, How to change the account that ASP.NET uses for this virtual directory to one that has rights to the SQL Server box. Or how to use impersonation set in the Web.config file for the asp...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
1
by: Ravi | last post by:
HI all, we r using db2 V 8.2, when i am trying to change data type ie. SMALLINT to INTEGER(no data in the table), iam getting this error messege. Pl. help me slove the error. ERROR is ...
6
by: Jan | last post by:
Hi: I have created a secured database for a client. For various reasons, I don't want the client to have full persmissions for the database; they aren't in the admins group. I have instead tried...
9
by: KDawg44 | last post by:
Hi, I am brand new to Python. In learning anything, I find it useful to actually try to write a useful program to try to tackle an actual problem. I have a syslog server and I would like to...
11
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
6
by: AAaron123 | last post by:
I'm using the CreateUserWizard Web Server Control The error message when the passwords do not match is colored red. Red does not show well against my background so I like to change that color. I...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.