Hi, I need to include into my program exception handling on my fuction/objects in my
program but am unsure on how to go about this, i looked on the information that has
been given on this site and still am no closer to solving the issue, please could
anybody explain this too me or if possible show me on sum coding that i have
placed below:

There are two parts to proper exception handling: letting the stack unwind, and stopping it at the right time.

Letting the stack unwind means that you want to make it so that the stack can unwind without leaking resources. Usually this is achieved by wrapping your resources in objects that will release the resource when the object is destroyed.

Stopping it at the right time means catching the exception where you can do something about it. If there is any opportunity to retry, or prompt the user to ask again after fixing external problems, these are ideal spots. Logging fatal errors can is also be a reason to catch the exception, in this case near the top level (like in main).

08-25-2011

1troy123

do have any idea how i would include this within my code? all i kno is that i need to include three things try, catch and throw, however i dont kno how to use them in my coding, if you can please help, thanks

08-25-2011

1troy123

okay i have this so far can anybody please help me with the following error:error C2310: catch handlers must specify one type......or any that you might see happen

i found that this dosnt work my code crashes with it aswell as without it

08-25-2011

laserlight

Not likely, because the code within the try block does not look like it will throw or propagate an exception.

I think that you need to get an overview of what exceptions are about before you try to use them.

EDIT:

Quote:

Originally Posted by 1troy123

i found that this dosnt work my code crashes with it aswell as without it

That indicates a problem with your code, probably a logic error leading to undefined behaviour. Exception handling is not appropriate to fix that, though it could sometimes help you diagnose such problems.

08-25-2011

1troy123

i have to include some exception handling into my project and not sure where to put them, i have functions in my code that are under buttons and that was the only place i could think of putting them if u can help please do if im way off thenim sorry for wasting ur time, thanks

08-25-2011

tabstop

The only flaw I see in the code is possibly following a null pointer, should _head be equal to NULL (since you never check for such a thing). But that's not the kind of thing that throws an exception that I know of. Have you looked at your documentation as to what actually causes exceptions? Or perhaps you are supposed to be checking for NULL and throwing an logic_error exception in that case. You will probably get more guidance from the mysterious "they" who are forcing you to use exceptions, as presumably they have told (or will tell) you what kind of exceptions they want caught.

08-25-2011

1troy123

As i need some sort of exception handling in my project would it be possible for anybody to give me an idea of what i could possibley use exception handling for, i have a program that allows a user to input and store data into an external file, load data from said file and browse, delete and search for items in that file (using node and list), please if anybody can help!

08-26-2011

nvoigt

Quote:

As i need some sort of exception handling in my project

Can you explain why you need exception handling? Do you have a problem that needs to be fixed by it? If so, post code. Do you want to use exception handling to throw your own exceptions or just catch exceptions thrown by library functions? If so, what library?