Hi,
A module which I am calling may have a run time error. Now currently in
such case user gets message box saying run time error has occured. My aim is
to catch this runtime error and show a friendly message to the user. How can
this be done? I have tried putting a try catch block around function call
but runtime error is not caught.
--Manish Soni 3 1814
You *have* to (!!!) establish where exactly in your program the error can
occur. Most runtime errors I have dealt with, have to do with conversions
between and to strings. Put MessageBox.Show ("1"); 2,3,4 etc. all through
your problema area in your program and get it to produce an error. You will
then know where the error is occurring, then deal with that error. Allowing
the user to see bug messages is absolutely no good.
For instance:
try
{
some conversion giving x a value
}
catch
{
x = 0;
}
Yes and no.
First read the MSDN article. It points out quite clearly (and, IMHO,
correctly) that there are two kinds of exceptions in every program.
Exceptions that you can handle gracefully and continue executing, and
exceptions that you can't handle and have no choice but to shut down
the program.
In the former case, yes. You should figure out where the exception is
happening, trap it with a try...catch, and take remedial action.
In the latter case, you should allow the exception to bubble to the top
of the call stack and catch it in the AppDomain.Unhan dledException and
the Application.Thr eadException handlers. These handles should probably
log the details of the error in a log file somewhere, maybe send an
e-mail to someone in support, and present a pleasant message box to the
user saying nothing more than that something has gone horribly wrong,
the application must shut down now, and that they should call support.
On some occasions, this strategy is insufficient for dealing with fatal
exceptions, because you lose too much context by allowing the exception
to bubble to the top of the call stack, and the log messages are
missing important information. If this is the case, you should catch
the exception and wrap it in a new exception, adding the necessary
context information, and then throw that new exception and let it
bubble up into the global exception handlers.
Read the article: do not attempt to catch evey exception that can be
thrown by every call in your program. Catch only the ones that you can
deal with gracefully, and handle the rest globally. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Manish Soni |
last post by:
My C# code invokes some unamanged code. My goal is to somehow catch any time
error in the unmanaged code. I want to capture that a show a user friendly
exception to the end user.
-- Manish
|
by: cmay |
last post by:
FxCop complains every time I catch System.Exception.
I don't see the value in trying to catch every possible exception type
(or even figuring out what exceptions can be caught) by a given block
of code, when System.Exception seems to get the job done for me.
My application is an ASP.Net intranet site. When I catch an exception,
I log the stack trace and deal with it, normally by displaying an error
|
by: Chris Stankevitz |
last post by:
Hi,
I have a very large Visual c++ .net 2003 7.1 native c application
(approximately 500,000 lines of code). This application is a simulation
that frequently works with floating point numbers.
From time to time I do something bad -- for example divide by zero or try
to grow a float beyond numeric_limits<float>::max()
I told MSVC .net 2003 7.1 to "Break into the debugger" for ALL exceptions in
|
by: R. MacDonald |
last post by:
Hi,
I have a VB.Net application that dynamically calls unmanaged routines in
a DLL that has been created by Fortran (DVF v5).
The call to the DLL routine is within a Try/Catch block, but when one of
the DLL (Fortran) routines triggers a run-time error, the VB.Net
application terminates rather than catching the error.
Is there any way to be able to catch these Fortran run-time errors in
|
by: rodchar |
last post by:
hey all,
is there a way to catch all errors for my webform without using the
global.asax page?
thanks,
rodchar
| |
by: John Pye |
last post by:
Hi all
I have some C code that is giving me some 'nan' values in some
calculations. The C code is wrapped using SWIG to give me a Python
module that I am then exercising through a unittest suite.
It seems that I should expect the C code to throw floating point
exceptions (SIGFPE) and either the whole thing to abort, or for Python
to catch the errors and report them. Instead I'm getting neither. I
want to be able to track down the...
|
by: JJ |
last post by:
I only want to catch 404 errors at the application level (the rest are will
be handled by the customerrors section of the web.config). How do I check
for the error code in the
Application_Error of Global.asax ?
Thanks,
JJ
|
by: Donn Ingle |
last post by:
Yo,
An app of mine relies on PIL. When PIL hits a certain problem font (for
unknown reasons as of now) it tends to segfault and no amount of try/except
will keep my wxPython app alive.
My first thought is to start the app from a bash script that will check the
return value of my wxPython app and could then launch a new app to help the
user grok what happened and fix it.
Do you think that's a good idea, or is there another way to...
|
by: john |
last post by:
I wrapped some fortran code using F2PY and need to be able to catch
fortran runtime errors to run the following:
# "grid" is a wrapped fortran module
# no runtime errors incurred when run with the correct inputs for
filetype
#-------------------------------
def readGrid( self, coord='xyz' ):
mg = ( '.FALSE.', '.TRUE.' )
form = ( 'FORMATTED', 'UNFORMATTED' )
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |