Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Try / catch
icon5.gif  Try / catch [message #12418] Mon, 29 October 2007 10:56 Go to next message
pippo is currently offline  pippo
Messages: 17
Registered: October 2007
Location: Italy
Promising Member
Hello guru!
I have a question: try/catch handles only throw command or all exceptions?

I write this code:
int main()
{
   printf("start\n");
   try
   {
      int a = 0;
      int b = 0 / a;
   }
   catch(...)
   {
      printf("error\n");
   }
   printf("end\n");
   return(0);
}


Then, my program crash at line with "b=0/a".
With Ubuntu and U++ (debug mode and release mode)
and also with Windows Xp and Microsoft Visual Studio!!!
(Visual studio show a pop-up, to inform about exception).

WHY???

But, if I insert a "throw", then it jump correctly to catch(...).
I must verify all possible errors and insert my "throw"??? I don't belive!!!
Maybe I must active some flag?


10aa3a8774daeb994a88cc07572e2b6c
Re: Try / catch [message #12419 is a reply to message #12418] Mon, 29 October 2007 11:37 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1336
Registered: September 2007
Senior Contributor
On Windows Xp, U++ dev 10, it displays the correct functionality and there where no crashes. But if I try to debug it in a line-by-line mode, once it hits the exception, the cursor no longer moves when I press F10. Is step-over/step-through not supported after an exception?
Re: Try / catch [message #12426 is a reply to message #12418] Tue, 30 October 2007 09:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
pippo wrote on Mon, 29 October 2007 05:56

Hello guru!
I have a question: try/catch handles only throw command or all exceptions?

I write this code:
int main()
{
   printf("start\n");
   try
   {
      int a = 0;
      int b = 0 / a;
   }
   catch(...)
   {
      printf("error\n");
   }
   printf("end\n");
   return(0);
}


Then, my program crash at line with "b=0/a".
With Ubuntu and U++ (debug mode and release mode)
and also with Windows Xp and Microsoft Visual Studio!!!
(Visual studio show a pop-up, to inform about exception).

WHY???

But, if I insert a "throw", then it jump correctly to catch(...).
I must verify all possible errors and insert my "throw"??? I don't belive!!!
Maybe I must active some flag?



C++ and system exception are not the same thing.

Mirek
Re: Try / catch [message #12427 is a reply to message #12419] Tue, 30 October 2007 09:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 29 October 2007 06:37

On Windows Xp, U++ dev 10, it displays the correct functionality and there where no crashes. But if I try to debug it in a line-by-line mode, once it hits the exception, the cursor no longer moves when I press F10. Is step-over/step-through not supported after an exception?


Well, when exception occurs, it stops at instruction that caused exception. F10 tries to perform it again - this is standard behaviour with all debugers I know...

If you want to skip it (which most likely will break the program logic anyway), you need to change the IP.

Mirek
Re: Try / catch [message #12432 is a reply to message #12427] Tue, 30 October 2007 12:26 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
luzr wrote on Tue, 30 October 2007 09:39


Well, when exception occurs, it stops at instruction that caused exception. F10 tries to perform it again - this is standard behaviour with all debugers I know...

If you want to skip it (which most likely will break the program logic anyway), you need to change the IP.




In theory (IMHO) the debugger should step to catch block... I don't know very well GDB, but the Borland debugger had options to catch exceptions OR to leave the handling to the debugged program.

Ciao

Max

Previous Topic: File List with FtpClient
Next Topic: Template problem
Goto Forum:
  


Current Time: Sat Feb 16 17:11:55 CET 2019

Total time taken to generate the page: 0.00622 seconds