Exception when calling delete
Hi,
When i am trying to run the code below,it gives runtime<br>
exception. Although i am ctching the exception.<br>
Plz suggest something. I cann't check the pointer against<br>
NULL.
Code:
#include<iostream>
#include<stdexcept>
using namespace std;
void main()
{
char* p;
try
{
delete p;
}
catch(exception ex)
{
cout<<"hello"<<endl;
}
}
Regards<br>
Ram
Re: Exception when calling delete
Quote:
Originally posted by Ram_Gupta
Hi,
When i am trying to run the code below,it gives runtime<br>
exception. Although i am ctching the exception.<br>
Plz suggest something. I cann't check the pointer against<br>
NULL.
Code:
#include<iostream>
#include<stdexcept>
using namespace std;
void main()
{
char* p;
try
{
delete p;
}
catch(exception ex)
{
cout<<"hello"<<endl;
}
}
Regards<br>
Ram
You've not allocated anything with new.
try:
Code:
char* p = new char[100];
delete[] p;