If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian. 7 1391
Hi!
If the exception specified in the catch clause is thrown somewhere
inside the try clause, then it will be caught. However, since your catch
branch only has a rethrow statement, the same exception will be thrown
again - if you do not have any additional code in the catch part, it
will look like as if you had no try/catch at all.
What is the behavior you are expecting from this code?
-Lenard
Adrian < wrote:
If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian.
Supposig my sample code is all there is,
Could you add code to make it work?
Thanks.
"Lenard Gunda" <ms**@frenzy.hu wrote in message
news:OR******** ******@TK2MSFTN GP02.phx.gbl...
Hi!
If the exception specified in the catch clause is thrown somewhere
inside the try clause, then it will be caught. However, since your catch
branch only has a rethrow statement, the same exception will be thrown
again - if you do not have any additional code in the catch part, it
will look like as if you had no try/catch at all.
What is the behavior you are expecting from this code?
-Lenard
Adrian < wrote:
If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian.
Hi,
Possibly, but I still don't know how you want it to work? Do you want to
stop the exception from being rethrown, or what is it that you would
like to accomplish?
-Lenard
Adrian < wrote:
Supposig my sample code is all there is,
Could you add code to make it work?
Thanks.
"Lenard Gunda" <ms**@frenzy.hu wrote in message
news:OR******** ******@TK2MSFTN GP02.phx.gbl...
>Hi!
If the exception specified in the catch clause is thrown somewhere inside the try clause, then it will be caught. However, since your catch branch only has a rethrow statement, the same exception will be thrown again - if you do not have any additional code in the catch part, it will look like as if you had no try/catch at all.
What is the behavior you are expecting from this code?
-Lenard
> Adrian < wrote: If I code as follows
try { \\ do something } catch (.....Exception ) { throw; }
What should happen? A test program isn't doing what I had expected it would do. Hence this question.
Adrian.
Throw in catch block means current exception processing isn't enough or couldn't do it, and then; rethrow the exception object to the outer space, either try...catch pair or runtime/system exception handling mechanism.
"Adrian <" <no*@all.access ibleдÈëÏûÏ¢ news:45******** ************@dr eader2.news.tis cali.nl...
If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian.
On Wed, 29 Nov 2006 12:36:40 +0100, "Adrian <" <no*@all.access ible>
wrote:
>If I code as follows
try {
\\ do something } catch (.....Exception ) {
throw; }
What should happen? A test program isn't doing what I had expected it would do. Hence this question.
Adrian.
That depends on what you expected it to do. Currently your code just
rethrows the original exception, so unless you have another catch
statement somewhere the exception will remain uncaught and the program
will crash, at the point of your "throw", with an uncaught exception.
When I run:
static void Main() {
try {
int x = 20;
int y = 0;
int z = x / y;
}
catch (DivideByZeroEx ception) {
Console.WriteLi ne("Inside catch.");
throw;
}
Console.Write(" Press [Enter] to continue... ");
Console.ReadLin e();
}
I get "Inside catch." displayed on the console and then the program
crashes with an uncaught DivideByZero exception, as I would expect it
to. Also, the crash happened at the "throw" and not at the "z = x /
y". The original exception was correctly caught, it is the
re-throwing of the exception that is not caught and causes the actual
crash.
rossum
Thank you. I have no more questions.
It is clear now.
Adrian.
************
"rossum" <ro******@coldm ail.comwrote in message
news:9g******** *************** *********@4ax.c om...
On Wed, 29 Nov 2006 12:36:40 +0100, "Adrian <" <no*@all.access ible>
wrote:
If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian.
That depends on what you expected it to do. Currently your code just
rethrows the original exception, so unless you have another catch
statement somewhere the exception will remain uncaught and the program
will crash, at the point of your "throw", with an uncaught exception.
When I run:
static void Main() {
try {
int x = 20;
int y = 0;
int z = x / y;
}
catch (DivideByZeroEx ception) {
Console.WriteLi ne("Inside catch.");
throw;
}
Console.Write(" Press [Enter] to continue... ");
Console.ReadLin e();
}
I get "Inside catch." displayed on the console and then the program
crashes with an uncaught DivideByZero exception, as I would expect it
to. Also, the crash happened at the "throw" and not at the "z = x /
y". The original exception was correctly caught, it is the
re-throwing of the exception that is not caught and causes the actual
crash.
rossum
Thank you.
Adrian.
********
"Lyle Avery" <g.******@gmail .comwrote in message
news:u8******** ********@TK2MSF TNGP02.phx.gbl. ..
Throw in catch block means current exception processing isn't enough or
couldn't do it, and then; rethrow the exception object to the outer space,
either try...catch pair or runtime/system exception handling mechanism.
"Adrian <" <no*@all.access ibleD¡ä¨¨????¡é
news:45******** ************@dr eader2.news.tis cali.nl...
If I code as follows
try
{
\\ do something
}
catch (.....Exception )
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lixiaoyao |
last post by:
when I run the following code,it just generate "aborted",but the
anticipated answer is
"Caught \"char *\" exception" ,it seems to be no run the 'catch'
sentence.
please help!
#include <iostream>
using namespace std;
class CanThrowException
{
int *array;
|
by: Lasse Vågsæther Karlsen |
last post by:
From the book by Jeffrey Richter:
throw; will not change the origin of the exception, whereas
throw ex; will change the origin of the exception to this statement.
When I try the following program, I get this result:
3: at ... in c:\dev\vs.net\exceptiontest3\form1.cs:line 91
2: at ... in c:\dev\vs.net\exceptiontest3\form1.cs:line 101
1: at ... in c:\dev\vs.net\exceptiontest3\form1.cs:line 101
|
by: Kerri |
last post by:
Hi,
I am new to .NET
In my Error Logic on my Aspx pages when an error happens
it hits my catch statement where I throw an Exception.
My question is :
what is the difference between Thwo Exception and Throw
|
by: James Radke |
last post by:
Hello,
I am attempting to use the proper Try/Catch technique when accessing my
Microsoft SQL server database and have a question...
If I use something similar to the following:
Try
set up SQL connection
open the SQL connection
|
by: Jacek Dziedzic |
last post by:
Hi!
<OT, background>
I am in a situation where I use two compilers from different
vendors to compile my program. It seems that recently, due to
a misconfiguration, library conflict or my ignorance, with one
of the compilers I am having trouble related to libuwind.so,
which, to my knowledge, deals with the intricacies of unwinding
the stack upon an exception. Executables compiled with this
compiler crash with a SEGV after throw(), never...
| |
by: Ralph Moritz |
last post by:
Hi,
I've written a class called ConfigParser, which can be used to parse
config files. (Surprise!) I have overloaded the shift operators to
mimic the std iostreams. My question is, should overloaded operators
throw or not? Both are non-member friends of ConfigParser.
Cheers,
Ralph
|
by: Grizlyk |
last post by:
Hello
I want to understand the exception habdling in C++ more, because i
think no one can apply anything free (free - without remembering large
unclear list of rules and exceptions from rules and exceptions from
exception from rules) if he does not understand "why" the thing have
done excactly as is.
I know, some people do not agree with me at the point of "why".
|
by: Ranganath |
last post by:
Why is throw keyword considered as an operator?
|
by: jason.cipriani |
last post by:
Consider this program, which defines a template class who's template
parameter is the type of an exception that can be thrown by members of
the class:
=== BEGIN EXAMPLE ===
#include <iostream>
#include <string>
using namespace std;
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |