473,385 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

handling invalid memory access exception .

1 - How to cach invalid memory access exception ? Does standard library
provide any help ?

2 - Also when one write
catch(...)
{
//...........
}

what is wirtten inside catch block . How do we know type of exception
thrown in such case ?

Regards
Mangesh Sawant .

Apr 8 '06 #1
6 6510
mangesh <ma************@walla.com> wrote:
1 - How to cach invalid memory access exception ? Does standard
library provide any help ?
Instead of catching invalid memory access exceptions, you should
find the bug in your code and fix it, thus not getting the exception in
the first place.
2 - Also when one write
catch(...)
{
//...........
}

what is wirtten inside catch block . How do we know type of exception
thrown in such case ?


You don't. You used "..." after all. If you want to handle different
types of exceptions, use different catch handlers:

try
{
}
catch (std::exception const& e)
{
}
catch (char const* e)
{
}
catch (...)
{
}

hth
--
jb

(reply address in rot13, unscramble first)
Apr 8 '06 #2
> 1 - How to cach invalid memory access exception ? Does standard library
provide any help ?
Not every runtime error will trigger a C++ exception throwing. Indeed,
the behavior is undefined or platform dependent. In some systems, memory
access violation results in immediate core dump. So the best you can do
is to make sure you don't access invalid memory.

Accessing elements in standard containers through iterator can throw an
exception if the implementation uses a checked iterator. You should
consult the documentation. In general, you should always check the
iterator before you dereference it.

There are also safe alternatives to accessing elements in the standard
library. For example, use vector<>::at rather than vector<>::operator[]
is the performance drop isn't an issue to your program.

2 - Also when one write
catch(...)
{
//...........
}

what is wirtten inside catch block . How do we know type of exception
thrown in such case ?
You don't. That's why you should only use this when you don't care about
the type of exception thrown.

Regards
Mangesh Sawant .

Regards,
Ben

Apr 8 '06 #3
mangesh wrote:
1 - How to cach invalid memory access exception ?
In standard C++, the behavior is undefined if you try to do an invalid
memory access. Some implementation might throw an exception, but I think
most don't. However, there are special memory debugers like valgrind that
you can run your program in, and it can give you detailed information about
any irregularities.
Does standard library provide any help ?
No.
2 - Also when one write
catch(...)
{
//...........
}

what is wirtten inside catch block . How do we know type of exception
thrown in such case ?


We don't.

Apr 8 '06 #4
Jakob Bieling <ar****************@rot13.com> wrote:
: mangesh <ma************@walla.com> wrote:

: > 1 - How to cach invalid memory access exception ? Does standard
: > library provide any help ?
How about using signal() or sigset() with SIGSEGV?

: Instead of catching invalid memory access exceptions, you should
: find the bug in your code and fix it, thus not getting the exception in
: the first place.

You are assuming the invalid memory access is due to a bug in the code.
What if it is not?
Jun 23 '06 #5
> How about using signal() or sigset() with SIGSEGV?

: Instead of catching invalid memory access exceptions, you should
: find the bug in your code and fix it, thus not getting the exception in
: the first place.

You are assuming the invalid memory access is due to a bug in the code.
What if it is not?

accessing memory mapped files together with sparse files and the system
running out of disk space to back this sparse file may cause exceptions on
Windows and signals on UNIXs.
I certainly prefer exceptions over signals.

Jun 26 '06 #6

Thanks for reply .
One qwestion , if exception is not due to mistake in my code then what
else can
cause exception . Can included libraries cause excption , these are
generaly well
tested .

Regards ,
Mangesh Sawant .

Jun 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: garyolsen | last post by:
In C++ what kind of unexpected conditions should be handled as exceptions? Besides dividing by 0, bad memory allocation, what're the most popular exceptions? When should not use exception,...
34
by: rawCoder | last post by:
I have read that Exception Handling is expensive performance wise ( other than Throw ) , but exactly how ? Please consider the following example ... ////////////////// Code Block 1...
3
by: Stephen Witter | last post by:
I have the following example to catch more than one error. I am new to error handling in .net so I am wondering if the following is an exceptable approach: Sub LinkButton1_Click(sender As Object,...
4
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
2
by: Adrian Burka | last post by:
HELP! I have written a web service, and a program in C# using Microsoft Visual C#.NET to interact with the web service. Exception handling isn't working in my application, though. One function...
2
by: Susan Baker | last post by:
Hi, I am writing a Win32 DLL. I want to be able to handle any SEGVs (segmentation violations) gracefully, by using an error handler of sorts. Currently, if a user of my DLL (typically a VB...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
16
by: NewToCPP | last post by:
I have seen at several places that C++ programmers writing for RealTime Embedded applications dont use Exception Handling. They dont like Throw/catch concept. WHY? Thanks.
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.