472,783 Members | 1,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1555
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

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.