473,394 Members | 1,813 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,394 software developers and data experts.

Complex if statement.

Exception innerEx;
HttpException checkException ;
checkException = (HttpException)appException;
innerEx = checkException.InnerException;
if (innerEx != null && innerEx.GetType() == typeof(ViewStateException))
{
ErrNotify.LogError(msg, Request.Path, ErrorLevel.ErrorWarning);
}

Will the second part of my if statement execute when innerEx is null? Is
there a way to it prevent from executing?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)
May 30 '06 #1
9 5960
Arne,

No, in C#, logical expressions short circuit themselves if it can not
effect the result.

So, in this case, if the first part (innerEx != null) is false, since
you are using a logical and, it will not execute "innerEx.GetType() ==
typeof(ViewStateException)"

With a logical or statement, if the first part evaluates to true, then
the second part will not be evaluated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Arne Garvander" <Ar***********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Exception innerEx;
HttpException checkException ;
checkException = (HttpException)appException;
innerEx = checkException.InnerException;
if (innerEx != null && innerEx.GetType() == typeof(ViewStateException))
{
ErrNotify.LogError(msg, Request.Path, ErrorLevel.ErrorWarning);
}

Will the second part of my if statement execute when innerEx is null? Is
there a way to it prevent from executing?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)

May 30 '06 #2
On Tue, 30 May 2006 13:51:02 -0700, Arne Garvander wrote:
Exception innerEx;
HttpException checkException ;
checkException = (HttpException)appException;
innerEx = checkException.InnerException;
if (innerEx != null && innerEx.GetType() == typeof(ViewStateException))
{
ErrNotify.LogError(msg, Request.Path, ErrorLevel.ErrorWarning);
}

Will the second part of my if statement execute when innerEx is null? Is
there a way to it prevent from executing?


No. If the first part of the boolean expression results to false it will
stop there and not even try to evaluate the second part since there would
be no point. But you can see by yourself anyway. That behaviour must be
documented somewhere on MSDN but i can't find where.
May 30 '06 #3
Mehdi wrote:
On Tue, 30 May 2006 13:51:02 -0700, Arne Garvander wrote:
Exception innerEx;
HttpException checkException ;
checkException = (HttpException)appException;
innerEx = checkException.InnerException;
if (innerEx != null && innerEx.GetType() == typeof(ViewStateException))
{
ErrNotify.LogError(msg, Request.Path, ErrorLevel.ErrorWarning);
}

Will the second part of my if statement execute when innerEx is null? Is
there a way to it prevent from executing?


No. If the first part of the boolean expression results to false it will
stop there and not even try to evaluate the second part since there would
be no point. But you can see by yourself anyway. That behaviour must be
documented somewhere on MSDN but i can't find where.


It's documented under Conditional Logical Operators.
See Hejlsberg "The C# Programming Language" (ISBN 0321154916, p218) and
online search (F1) on && Operator in Visual C# Express 2005.

Eddie
May 30 '06 #4
If you use the && operator then it will not evaluate the right-hand
side if the left-hand side is false.

If you use the & operator then it will evaluate both sides regardless
of the value of the left-hand side.

May 30 '06 #5

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uf**************@TK2MSFTNGP02.phx.gbl...
Arne,

No, in C#, logical expressions short circuit themselves if it can not
effect the result.


To be precise, the operators && and || short-circuit. The operators & and
|, which can also be used in logical expressions [1], do not.

1. Note that this is different from C, C++, and Java, in which & and | are
bitwise operators only.
May 30 '06 #6
Mike Schilling <ap@newsgroup.nospam> wrote:

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uf**************@TK2MSFTNGP02.phx.gbl...
Arne,

No, in C#, logical expressions short circuit themselves if it can not
effect the result.


To be precise, the operators && and || short-circuit. The operators & and
|, which can also be used in logical expressions [1], do not.

1. Note that this is different from C, C++, and Java, in which & and | are
bitwise operators only.


Not sure where you get that idea about Java from:

public class Test
{
public static void main(String[] args)
{
boolean a = true;
boolean b = false;

System.out.println (a&b);
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 31 '06 #7

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike Schilling <ap@newsgroup.nospam> wrote:

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uf**************@TK2MSFTNGP02.phx.gbl...
> Arne,
>
> No, in C#, logical expressions short circuit themselves if it can
> not
> effect the result.


To be precise, the operators && and || short-circuit. The operators &
and
|, which can also be used in logical expressions [1], do not.

1. Note that this is different from C, C++, and Java, in which & and |
are
bitwise operators only.


Not sure where you get that idea about Java from:

public class Test
{
public static void main(String[] args)
{
boolean a = true;
boolean b = false;

System.out.println (a&b);
}
}


I'll be damned. I stand correct:ed: boolean & and | are exactly the same in
Java as in C#. But in all the hundreds of thousands of lines of Java I've
read through, I don't recall ever seeing them used.
May 31 '06 #8
Mike Schilling <ap@newsgroup.nospam> wrote:

<snip>
I'll be damned. I stand correct:ed: boolean & and | are exactly the same in
Java as in C#. But in all the hundreds of thousands of lines of Java I've
read through, I don't recall ever seeing them used.


Likewise - but that's true in C# for me as well :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 31 '06 #9
Funny, I'm sure I posted this yesterday, but it seems to have slipped
into the ether...

The second part of the if() statement can be written as:
if (innerEx != null && innerEx is ViewStateException)

With the proviso that your method would be true if innerEx is
specifically a ViewStateException, while using "is" would be true if it
is a ViewStateException or any class derived from ViewStateException.

Further, "is" is safe for nulls, so the entire if() can be written as:
if (innerEx is ViewStateException)

which, while not answering your question, neatly avoids it.

Arne Garvander wrote:
Exception innerEx;
HttpException checkException ;
checkException = (HttpException)appException;
innerEx = checkException.InnerException;
if (innerEx != null && innerEx.GetType() == typeof(ViewStateException))
{
ErrNotify.LogError(msg, Request.Path, ErrorLevel.ErrorWarning);
}


May 31 '06 #10

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

Similar topics

3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
8
by: J.Haan | last post by:
Hi all. I'm currently coping with a problem on which I hope you could shed some light. Imagine the following: I have table in DB2 8.1 (.5) which is defined as: table test { t1 smallint,...
6
by: Hardy | last post by:
One of my customers have a sql statement totaled more than 400 lines, about 40KB. when excuted, error arrised saying "SQL0101N The statement is too long or too complex". I tried one of his...
3
by: Susie Swint | last post by:
I have the following IIf statement which worked in Access 95 but will not work in Access 2002. The error message I get is that the expression is typed incorrectly, or is too complex to be...
3
by: Kevin Rollo | last post by:
I'm playing with a generic routine to export data, the concept is to have a list of data driven templates defining what fields to output. Evaluating a simple variable field name in the function...
2
by: Ben de Vette | last post by:
Hi, I'm using the querybuilder when updating a record in a table (Access). However, I get a "Query is too complex" message. The Primary key is autonumbered. Why is it making such a complex...
6
by: Jon Bilbao | last post by:
I´m trying a select clause in two steps because it´s too complex. First: SELECT Reference, Results.idEnsayo, Results.Num_taladro, min(Results.dTime) + 500 AS tIni, max(Results.dTime) - 500 AS...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
1
by: Rahul Babbar | last post by:
Hi, I ran the scripts in a file from Command Line Processor and it gave the error for all the constraints being added, but not the indexes being added. For a simple statement like Alter...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
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...
0
tracyyun
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...

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.