Hi,
I have a code like this structure,
try{
.. some function call...
}
catch (...){
return NULL;
}
during those function calls, the code has a bug which calls STL
vector erase() to delete a NULL pointer, but the problem is catch(...)
does not catch the error, instead I get a segment fault.
What is the problem? 8 1871
John Black wrote: I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error, instead I get a segment fault.
What is the problem?
Hard to say. 'delete'ing a NULL pointer is explicitly allowed and
is a NOP. Could it be that it's calling a member function using
a pointer that is NULL, thus dereferencing it? That's not allowed.
Exceptions produced by the execution environment do not always fall
into C++ "catchable" category. Ask in the newsgroup for your OS or
your compiler to see if there is a compiler- or platform-specific
solution.
Victor
"John Black" <bl***@eed.com> wrote in message
news:41**************@eed.com... Hi, I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error, instead I get a segment fault.
What is the problem?
As Victor said, deleting a NULL pointer is not an error. There are many
programming errors in C++ which result in the dreaded "undefined behavior".
In such cases there is NO guarantee that an exception will be thrown. In
fact there are no guarantees of any kind, hence the term.
--
Cy http://home.rochester.rr.com/cyhome/
* John Black: Hi, I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error
'catch' does not catch errors, it catches exceptions.
§23.1/10: "no erase() ... function throws an exception".
instead I get a segment fault.
What is the problem?
That you call erase with a NULL pointer instead of a valid iterator.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Cy Edmunds wrote: "John Black" <bl***@eed.com> wrote in message news:41**************@eed.com... Hi, I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error, instead I get a segment fault.
What is the problem?
As Victor said, deleting a NULL pointer is not an error. There are many programming errors in C++ which result in the dreaded "undefined behavior". In such cases there is NO guarantee that an exception will be thrown. In fact there are no guarantees of any kind, hence the term.
-- Cy http://home.rochester.rr.com/cyhome/
that's a little scary to know this...I had relied heavily on catch (...) to
prevent my software from crash...is there any way to better handle error ?
John Black wrote: Cy Edmunds wrote:
"John Black" <bl***@eed.com> wrote in message news:41**************@eed.com...
Hi, I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error, instead I get a segment fault.
What is the problem?
As Victor said, deleting a NULL pointer is not an error. There are many programming errors in C++ which result in the dreaded "undefined behavior". In such cases there is NO guarantee that an exception will be thrown. In fact there are no guarantees of any kind, hence the term.
-- Cy http://home.rochester.rr.com/cyhome/
that's a little scary to know this...I had relied heavily on catch (...) to prevent my software from crash...is there any way to better handle error ?
Certain errors can only be handled by OS-specific means. Please ask in
a newsgroup dedicated to your OS for more information.
V
John Black wrote: ... I have a code like this structure,
try{ .. some function call... } catch (...){ return NULL; }
during those function calls, the code has a bug which calls STL vector erase() to delete a NULL pointer, but the problem is catch(...) does not catch the error, instead I get a segment fault. ...
'catch' does not catch "errors". It catches C++ exceptions thrown by
'throw'. If you program crashes, 'catch' won't help you to prevent this.
Some implementations might provide certain facilities that allow you to
"convert" various hardware/OS-specific crash situations into C++
exceptions (manually or automatically), but it depends on the concrete
implementation, can be expensive and not always bulletproof.
--
Best regards,
Andrey Tarasevich
> that's a little scary to know this...I had relied heavily on catch (...)
to prevent my software from crash...is there any way to better handle error ?
If your software crashes, it's faulty and should be treated as one. This
sounds as an dangerous approach to program design.
jive
"jive" <ji**@nospam.invalid> wrote in message
news:cg***********@news.cc.tut.fi... that's a little scary to know this...I had relied heavily on catch (...) to prevent my software from crash...is there any way to better handle error
? If your software crashes, it's faulty and should be treated as one. This sounds as an dangerous approach to program design.
jive
No, its not. It's called fault tolerant programming. Such a program should
*never* crash. It should detect such detrimental problems and handle them
accordingly. This "handling" can be anything appropriate for the design of
the systems, such as restarting the process or rebooting the system.
Usually when rebooting (which can be as quick as a few nanoseconds or take
several minutes), a backup computer takes over until the master is health
again. Before "fixing" the problem the system can save information on it in
persistent storage so it can be invested during post-mission analysis.
DrX This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gary.Hu |
last post by:
I was trying to catch the Arithmetic exception, unsuccessfully.
try{
int a = 0, b = 9;
b = b / a;
}catch(...){
cout << "arithmetic exception was catched!" << endl;
}
After ran the program,...
|
by: Noor |
last post by:
please tell the technique of centralize exception handling without try catch
blocks in c#.
|
by: Jacek Dziedzic |
last post by:
Hi!
In my main() function I have a last-resort exception construct that
looks
like this:
int main() {
try {
// ... program code
}
|
by: Pohihihi |
last post by:
I was wondering what is the ill effect of using try catch in the code, both
nested and simple big one.
e.g.
try
{
\\ whole app code goes here
} catch (Exception ee) {}
|
by: Benny |
last post by:
Hi,
I have something like this:
try
{
// some code
}
catch // note - i am catching everything now
{
|
by: VB Programmer |
last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally.
Example: In order to close/dispose a db connection you have to dim the
connection outside of the Try Catch Finally...
|
by: will |
last post by:
Hi all. I've got an question about how to catch an exception.
In Page_Load, I place a DataGrid, dg1, into edit mode. This will
call the method called GenericGridEvent. GenericGridEvent will
call...
|
by: Ralph Krausse |
last post by:
I created a try/catch/finally but when an expection is thrown, the
catch does not handle it... (I know this code is wrong, I want to
force the error for this example)
try
{
DataSet ds = new...
|
by: l.woods |
last post by:
I want to set up my CATCH for a specific exception, but I really don't know
which one of the multitude that it is. I am getting the exception now with
Catch ex as Exception
but I want to be...
|
by: cj |
last post by:
Another wish of mine. I wish there was a way in the Try Catch structure
to say if there wasn't an error to do something. Like an else
statement. Try Catch Else Finally.
Also because I...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |