Error handling (try catch)
Hi everyone!
Is there any way to catch or detect access violation error?
construction like
- try{
- str.clear();
- }
- catch(...){
- ...
- }
should throw error, but it doesn’t.
1 reply
The access violation error isn’t thrown (exceptions are thrown not errors) – it occurs when you access memory that you don’t own.
Anyway you can initialize your pointers with 0 (null pointer) and then first check for 0 and only then call a member-function (to be a little more safer you can assign 0 to the pointer after you delete it then you detect the attempt to call function after the pointer is deleted)
You must log in to post a reply. Not a member yet? Register here!


