March 1, 2012

qxoz qxoz
Area 51 Engineer
1027 posts

Error handling (try catch)

 

Hi everyone!
Is there any way to catch or detect access violation error?
construction like

  1. QString *str;
  2. try{
  3.     str.clear();
  4. }
  5. catch(...){
  6.     ...
  7. }

should throw error, but it doesn’t.

1 reply

March 1, 2012

Zlatomir Zlatomir
Ant Farmer
367 posts

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)

 
  ‹‹ ocr in c++      why does the following recursive directory creation fail? ››

You must log in to post a reply. Not a member yet? Register here!