Hi all
I am working in VC++ domain. i need one help regarding vc++ exception handling. how to use exception handling in vc++? how to get the error message? how to avoid the runtime error. i used some exception in vc++ but in that i cant get the error message...
help me..
Regards
Sam
6 3912
You use the standard try/catch/throw of C++.
Do you have a code sample?
You use the standard try/catch/throw of C++.
Do you have a code sample?
try{
int a=10;
int b;
b=a/0;
}
catch(CExceptio n* e)
{
some codes
}
here i want to catch the error.. but i cant get it...
if you know help me
I don't believe a/0 throws an exception. You need to call a function and have that function throw the exception you want to catch.
Your code should look like this: -
try{
-
int a=10;
-
int b;
-
b = MyFunction(a,0);
-
}
-
catch(CException* e)
-
{
-
some codes
-
}
-
-
//Where:
-
-
int MyFunction(int first, int second)
-
{
-
if (second == 0) throw new CException;
-
-
return first/ second;
-
}
-
Thanks for your reply,
i worked with your code. but in that i am not getting any messages.
i used GETErrorMessage () and ReportError() function.
i cant get it. help me...
And also i dont know how to use exception like CMemoryExceptio n,
waiting for your valuable reply.
OK, I put this in _tmain(): -
int result = ATest(5,0);
-
-
cout << "Result is: " << result << endl;
-
The ATest function looks like my cocd from my last reply except I have got it to compile and execute: -
int ATest(int a, int b)
-
{
-
try
-
{
-
int* pb = &b;
-
*pb = MyFunction(a,b);
-
}
-
catch(CException* e)
-
{
-
cout << "Exception!!" << endl;
-
return 0;
-
}
-
return b;
-
}
-
-
-
-
int MyFunction(int first, int second)
-
{
-
if (second == 0) throw new CMemoryException;
-
-
return first/ second;
-
}
-
-
So, a call is made to ATest(). ATest trys MyFunction() passing in the two integers. If the second interge id 0, MyFunction() throws a MemoryException .
A CMemoryExceptio n IS-A CException. Therefore, it is caught using a CException pointer.
Try this code yourself with different values used in ther ATest() call in _tmain().
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 return
code (not generating error/exception) so it is more
compatible with other programming language.
|
by: Noor |
last post by:
please tell the technique of centralize exception handling without try catch
blocks in c#.
|
by: Master of C++ |
last post by:
Hi,
I am an absolute newbie to Exception Handling, and I am trying to
retrofit exception handling to a LOT of C++ code that I've written
earlier. I am just looking for a bare-bones, low-tech exception
handling mechanism which will allow me to pass character information
about an error and its location from lower-level classes.
Can you please critique the following exception handling mechanism in
terms of my requirements ?
|
by: tom |
last post by:
Hi,
I am developing a WinForm application and I am looking for a guide on where
to place Exception Handling. My application is designed into three tiers
UI, Business Objects, and Data Access Layer. My questions is where should I
put exception handling:
1) Should it be put in all significant methods in all layers?
2) Should I create an exception base class that will handle the errors and
pass useful error messages to the user?
|
by: C# Learner |
last post by:
Some time ago, I remember reading a discussion about the strengths and
weaknesses of exception handling. One of the weaknesses that was put
forward was that exception handling is inefficient (in the way of CPU
usage), compared to the "normal" practise returning values.
How true is this? Will using using exception handling, in general, be
much less efficient than returning values, or less efficient at all?
Just curious...
| |
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 user tasks should always be
included in a try/catch block that actually handles any exceptions that
occur (log the exception, display a message box, etc.).
2. Low-level operations that are used to carry out the high level tasks
|
by: Hasani \(remove nospam from address\) |
last post by:
I was reading a ppt ( http://www.gotdotnet.com/team/pdc/4064/tls310.ppt )
and came aross this statement.
"Users can leverage a destructor. The C++ compiler generates all the Dispose
code automatically, including chaining calls to Dispose. (There is no
Dispose pattern)"
but Dispose can thrown an exception. Is the exception supressed?
|
by: sparc |
last post by:
Hi,
I have a software with the source code for windows. It can't be compiled in
vc++ easily. Is it possible to set the break points in the source code using
vc++ or atleast create the project file to browse the source.
|
by: George2 |
last post by:
Hello everyone,
Such code segment is used to check whether function call or exception-
handling mechanism runs out of memory first (written by Bjarne),
void perverted()
{
try{
|
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: 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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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: 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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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.
| |