[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Try-Catch block unable to catch exception
From: |
Thomas Maeder |
Subject: |
Re: Try-Catch block unable to catch exception |
Date: |
Tue, 22 Jul 2008 07:01:23 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
kk <krishnakumar85@gmail.com> writes:
> char *str = 0;
>
> try
> {
> // int i = 0;
> // int j = 1/i; // Uncommenting this would not go into
> catch block. But gives "Floating Point Exception"
Division by 0 is undefined behavior. A platform may transform it into
an exception, but that certainly isn't a requirement.
> strstr(str,"hello"); // str is NULL -> exception!
Passing 0 here is undefined behavior. A platform ...
In both cases, the program is in an invalid state after the attempted
operation, and IMHO, anything but immediate termination of the program
is (at least) weird.
> Similar code was tried using VC++ on a windows system. It works. i.e,
> control does move to the catch block and execute as expected.
But in general, there is no telling how the program will behave.