473,672 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6558
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<>::opera tor[]
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
3415
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, instead, use regular function returns? Thanks!
34
2220
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 ////////////////////////////////// Try { for ( ... ){// Code that might throw exception} }catch(...){} //////////////////////////////////////////////////////////////////////////
3
1136
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, e As EventArgs) Try txtDate.text=("hi"/0) Catch ex As Exception if ex.GetType.ToString ="System.InvalidCastException" then Response.write("You have entered an invalid date.")
4
7609
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 (note that this class module represents the business layer of code NOT the gui layer): Public Function Test(ByVal Parm1 As Integer, ByVal Parm2 As Integer) As SqlDataReader ' Declare the SQL data layer class Dim oSQL As New...
2
8166
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 that is called checks to see if a password is correct, and if it's not, it throws an exception with the message "Invalid password". I have exception-handling code in my application, but it doesn't catch the error I'm expecting. Instead, it...
2
1268
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 programmer) passes a null (or invalid) pointer to my library - the entire application crashes, leaving shared memory, database connections etc in a "dirty" state. I would like a way of gracefully handling user "actions" like this - without crashing...
4
13536
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 database complains about a primary key violation (which is what I want) and an exception is thrown. The OnInserted event of the SqlDataSource provides access to the exception so, presumably, you can provide nice handling for various errors. For...
16
6931
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
3101
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{
0
8505
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8699
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7479
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6261
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4245
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1842
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.