Solved

500 POINTS, URGENT, PLZ HELP!!... PROBLEM WITH VARIABLES, TRY CATCH BLOCKS...

Posted on 2007-03-21
20
213 Views
Last Modified: 2010-03-31
try
{
check = false;
            }
catch (the exception)
{
}
try
{
      if (check ==true)
      {

>> I get an error saying that check variable is not found. I am certain its because its in different try catch blocks. Is there anyway that i can pass the variable to the next try catch block.

>>Or if there is any other way around this. The Try Catch blocks are both different, one being

-->>MessagingException


-->>SQLException
0
Comment
Question by:deepanp
  • 8
  • 6
  • 6
20 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767697
Define 'check' before first block
0
 

Author Comment

by:deepanp
ID: 18767705
-->Define 'check' before first block

--

Hi,

you mean Boolean check = false;

>>?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 18767713
boolean check = false;
0
 
LVL 92

Expert Comment

by:objects
ID: 18767714
try the following:

boolean check = false;   // declare variable *outside* try/catch blocks
try
{
   check = false;
}
catch (the exception)
{
}
try
{
      if (check ==true)
      {
0
 

Author Comment

by:deepanp
ID: 18767729
hey objects,

i'm sorry, i should have also mentioned that the boolean check = false; --> is in the catch block of the first try catch blocks.
0
 
LVL 92

Expert Comment

by:objects
ID: 18767746
> i'm sorry, i should have also mentioned that the boolean check = false; --> is in the catch block of the first try catch blocks.

yes, I'm saying you need to move it *outside* so its visibale in both blocks
See the code I posted above
0
 
LVL 92

Expert Comment

by:objects
ID: 18767755
variables declared inside a try/catch block are only visible (scope) withing that try/catch block
0
 

Author Comment

by:deepanp
ID: 18767757
-->>yes, I'm saying you need to move it *outside* so its visibale in both blocks
See the code I posted above

-->>i understand that, however, if a catch is caught, i need the boolean to be false, otherwise true. so to my knowledge, i believe this will not work if i have it outside of the catch, as the var will always be false.
0
 

Author Comment

by:deepanp
ID: 18767766
-->>variables declared inside a try/catch block are only visible (scope) withing that try/catch block

->Is there any way where i can catch both of teh exceptions then, essentially joining the try, catch blocks. Or any way to define the variable to be called from outside, idea if possible like making it Perminent throughout...
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 18767795
boolean check = true;   // declare variable *outside* try/catch blocks
try
{
}
catch (the exception)
{
   check = false;
}
try
{
      if (check ==true)
      {
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:deepanp
ID: 18767827
-->>HAHA,

-->>:P.....

-->>I started to think.. and logically thought of a for loop outside of all of this try catch blocks, then implemented the

-->>break statement when a catch was caused... making the loop break... the loop is only in one iteration...


:P


-->>Practical Method, i'd say hey?

-->>Thanks Guys...
-->>I'll get the points refunded.

0
 
LVL 92

Expert Comment

by:objects
ID: 18767849
what i suggested above will work and avoids need for using break :)
0
 

Author Comment

by:deepanp
ID: 18767868
-->>The break, i'd say is a much easier method, Don't ask why.

-->>However you have figured the solution.

-->>Therefore points awarded to you.

-->>Thanks Objects and CEHJ...For all the Help...:-D...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767878
Move the statement to where i mentioned. You can do what you like with it then
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767889
deepanp - can you explain why you accepted a comment that repeats the answer i'd already given?
0
 

Author Comment

by:deepanp
ID: 18767924
-->>CEHJ - I'm sorry, as reading above, I noticed I missed a message from you.

-->>If its possible, I will contact admin, and askthem to split points instead..

-->>However, If this is possible.

-->>If not then I do apologise.

-->>I might well be posting another problem soon - :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767938
It is possible. I'll alert them for you
0
 

Author Comment

by:deepanp
ID: 18767943
-->>Please send me the link, if you are posting the message...

-->>Or do you want me to. If so, where isit again to post the issues...?
0
 
LVL 92

Expert Comment

by:objects
ID: 18767954
What CEHJ suggested would not work. You were setting the flag in the wrong place.
What I suggested was not the same as what CEHJ stated, a split is not necessary.

Try his suggestion if you like, check will never get set :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18773348
:-)

Let me know if you can see the difference between the accepted and assisted - i can't ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 68
split string containing \r\n in Java 46 38
why cannot we forward request once the response is committed 2 33
java stored proc example 9 19
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now