473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pure scope and try catch scoping idea

try catch blocks create a new scope

i don't think that they should

for example, to add error handling to this statement:

int x = 1;

you have to rewrite it as a seperate declaration and assignment:

int x;
try {
x = 1;
} catch {}

maybe if try catch used different braces to show new scope is not
necessary:

try [
//new scope not needed here
int x = 1;
] catch (Exception exc) {
//new scope needed here
}

this would allow error handling to be non-destructively added and
removed from code

plus it should be possible in C# to do this

int x = 1;
{
int y = 1;
}

ie: have a scope for no other purpose than having a scope

rather than

do {
//create new scope for scopes sake
} while (false)

Jan 12 '07 #1
3 1876
Hi John,

comments inlined.

"John Rivers" <fi*****@btinternet.comschrieb im Newsbeitrag
news:11**********************@11g2000cwr.googlegro ups.com...
try catch blocks create a new scope

i don't think that they should

for example, to add error handling to this statement:

int x = 1;

you have to rewrite it as a seperate declaration and assignment:

int x;
try {
x = 1;
} catch {}

maybe if try catch used different braces to show new scope is not
necessary:

try [
//new scope not needed here
int x = 1;
] catch (Exception exc) {
//new scope needed here
}
Even that wouldn't work. If the assignment failed, x is in an unassigned
state. That's why x would be unusable in the catch clause. You could assign
to it. But reading would result in a compiler error: Use of unassigned
variable. So the assignment has to be inside of the catch clause anyway
>
this would allow error handling to be non-destructively added and
removed from code

plus it should be possible in C# to do this

int x = 1;
{
int y = 1;
}

ie: have a scope for no other purpose than having a scope

But this already works in C#. I even used it once.
So there is no use for that:
>
rather than

do {
//create new scope for scopes sake
} while (false)

Jan 12 '07 #2

John Rivers wrote:
try catch blocks create a new scope

i don't think that they should

for example, to add error handling to this statement:

int x = 1;

you have to rewrite it as a seperate declaration and assignment:

int x;
try {
x = 1;
} catch {}

maybe if try catch used different braces to show new scope is not
necessary:

try [
//new scope not needed here
int x = 1;
] catch (Exception exc) {
//new scope needed here
}

this would allow error handling to be non-destructively added and
removed from code

plus it should be possible in C# to do this

int x = 1;
{
int y = 1;
}

ie: have a scope for no other purpose than having a scope

rather than

do {
//create new scope for scopes sake
} while (false)
John,

Braces can already be used to create "pure scopes". And, I happen to
like that a new scope is created for try-catch-finally blocks. Plus,
it's easy to remember the rule that braces always narrow the scope.

Brian

Jan 12 '07 #3
good point re: refering to unassigned variables in catch clause

thanks for pointing out you can already use { } - for some reason I
thought you couldn't
On Jan 12, 4:29 pm, "Christof Nordiek" <c...@nospam.dewrote:
Hi John,

comments inlined.

"John Rivers" <firs...@btinternet.comschrieb im Newsbeitragnews:11**********************@11g2000cw r.googlegroups.com...


try catch blocks create a new scope
i don't think that they should
for example, to add error handling to this statement:
int x = 1;
you have to rewrite it as a seperate declaration and assignment:
int x;
try {
x = 1;
} catch {}
maybe if try catch used different braces to show new scope is not
necessary:
try [
//new scope not needed here
int x = 1;
] catch (Exception exc) {
//new scope needed here
}Even that wouldn't work. If the assignment failed, x is in an unassigned
state. That's why x would be unusable in the catch clause. You could assign
to it. But reading would result in a compiler error: Use of unassigned
variable. So the assignment has to be inside of the catch clause anyway
this would allow error handling to be non-destructively added and
removed from code
plus it should be possible in C# to do this
int x = 1;
{
int y = 1;
}
ie: have a scope for no other purpose than having a scopeBut this already works in C#. I even used it once.
So there is no use for that:


rather than
do {
//create new scope for scopes sake
} while (false)- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Jan 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Johansson | last post by:
Hello Experts!! When you instansiate varaibles(object) you can do so in four different scops which are. Within a block which is called Local or block scope . Within a function which is called...
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
7
by: Michael G | last post by:
I am a little surprised that the following that $x is visible outside of the scope in which it is (?)defined(?) (not sure if that is the correct term here). I am trying to find where in the php...
3
by: Carmella | last post by:
Is it possible for a class to create an instance of a private nested class which raises events and then listen for those events? In the example below, when InnerClass sings, OuterClass should say...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
14
by: gerald.dalley | last post by:
I've been trying to pin down the scoping rules for temporary variables in C++. I know that doing something like: string s("abc"); const char *t = (s+"def").c_str(); cout << t; is invalid...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
8
by: Hoi Wong | last post by:
With the XSLT 1.0 engine that I was forced to use, I have to parse old XML scripts where the number (to be parsed and saved into $EPISODE_NUMBER_RAW) that I want to parse is written with a comma...
2
by: ray | last post by:
Hi, all, foreach($array as $k =$v) { $foo = ...; } echo $foo; Is it allowed to access the $foo variable that is created within the loop from outside of the loop? I think it isn't allowed,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
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,...
0
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...

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.