exception

can
we use all exceptions available in Java
lik try ,catach so , similarly in  C++
ravndraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexVirochovskyCommented:
Yes, you can ! Example:
//***************************************************************
// Win32 Programming for Windows NT
//
// Sample
// by Johannes Plachy 1998/1999
// JPlachy@qualityservice.com
//
//***************************************************************


#include <windows.h>
#include <stdio.h>

/* exception filter function */
DWORD filter()
{
   printf("Hello");
   return EXCEPTION_EXECUTE_HANDLER;
}

void main(void)
{

   LPSTR p;

   try
   {
      try
      {
         p = (LPSTR)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_READONLY);
         *p = 7;    /* will fail - read only! */
         exit(34);
      }
      catch(...)
      {
         Beep(2000, 100);
         Sleep(1000);
         printf(" ");
      }
   }
   except (filter())
   {
      Beep(1000, 100);
      Sleep(1000);
      printf("World\n");
   }
}

See more details in Windows Doc about catch,try,finally...
Alex
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
This is Win32 SEH, which is completely different to C++ exceptions...
0
mikeblasCommented:
> This is Win32 SEH, which is completely different to C++ exceptions...

So what? The question is nearly nonsensical, so nearly any answer is worth trying. Spin the wheel and try your luck!

..B ekiM
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jkrCommented:
>>So what?

So MS. In case you forgot, not every computer runs Windows....

BTW: This is the C++ area, Windows is next door ;-)

0
KangaRooCommented:
It would at least make sense to seperate and explain the two (C++ based exceptions) and Windows SEH...
As general as the question was put, I'd say C++ exceptions are in order.
0
mikeblasCommented:
> BTW: This is the C++ area, Windows is next door ;-)

People here very frequently ask (and answer) questions in the wrong order.

..B ekiM
0
mikeblasCommented:
And I frequently say "order" when I mean "area".

..B ekiM
0
SridharReddyCommented:
#include <string>
#include <iostream>
using namespace std;

int main()
{
//code line 1
//code line 2
//....
//....
// code likely to 'throw' an exception
// don't put try catch for the entire code.
try{
    //code line n
    //code line n+1
// if(exceptional condition)
{
     throw object;
//(object may be a real object or a basic data type.. I prefer a real object with info about the point of occurence, module, error code etc )

} // if

}// try
// nothing here between try & catch.
catch(class& E) // class is the type of 'object'. i.e. an int or the class name itself.
{
E.Log();
E.Notify();
E.WhatEver();
throw; // to the next layer or the OS if this is the last layer/module.
In this case it is the last layer as it is the main program.

}//catch code

// take care of all unknown exceptions
catch(...)
{
className object; // exception handler class.

object.Log("Unkown Exception");
throw object;
}

//code line n+100
//*....
....*//

}





0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.