473,811 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VC++ Exception Handling

11 New Member
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
May 24 '07 #1
6 3912
sicarie
4,677 Recognized Expert Moderator Specialist
I can't give you one with authority - I don't use VC++, but check these out:

http://www.google.com/search?hl=en&q...=Google+Search
May 24 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
You use the standard try/catch/throw of C++.

Do you have a code sample?
May 24 '07 #3
sathiyamurthy
11 New Member
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
May 25 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
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:

Expand|Select|Wrap|Line Numbers
  1. try{
  2. int a=10;
  3. int b;
  4. b =     MyFunction(a,0);
  5. }
  6. catch(CException* e)
  7. {
  8. some codes
  9. }
  10.  
  11. //Where:
  12.  
  13. int MyFunction(int first, int second)
  14. {
  15.     if (second == 0) throw new CException;
  16.  
  17.     return  first/ second;
  18. }
  19.  
May 25 '07 #5
sathiyamurthy
11 New Member
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.
May 28 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
OK, I put this in _tmain():

Expand|Select|Wrap|Line Numbers
  1.  int result = ATest(5,0);
  2.  
  3.     cout << "Result is: " << result << endl;
  4.  
The ATest function looks like my cocd from my last reply except I have got it to compile and execute:

Expand|Select|Wrap|Line Numbers
  1. int ATest(int a, int b)
  2. {
  3.    try
  4.    {
  5.      int* pb = &b;
  6.      *pb =    MyFunction(a,b);
  7.     }
  8.     catch(CException* e)
  9.     {
  10.         cout << "Exception!!" << endl;
  11.         return 0;
  12.     }
  13.     return b;
  14. }
  15.  
  16.  
  17.  
  18. int MyFunction(int first, int second)
  19. {
  20.     if (second == 0) throw new CMemoryException;
  21.  
  22.     return  first/ second;
  23. }
  24.  
  25.  
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().
May 28 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2892
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.
7
6010
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
2755
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 ?
2
2598
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?
9
2542
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...
44
4236
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
9
1254
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?
1
1076
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.
1
3114
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{
0
9728
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, 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...
0
10389
jinu1996
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...
1
10402
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,...
0
10135
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 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...
1
7670
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 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...
0
6890
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();...
0
5554
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...
1
4339
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
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.