By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

strange behavior of class: lose data on throw exception.

P: n/a
Hallo,
I use a class vith a vaiables.
When a function throws an exception it seems to loose data:

....
$c=new myclass();
try{
$a->var1=1;
$a->function_throw_exception(); <--- this throws an exception
...
}
catche(exception $e)
{
$a->var1; <--- is empty ?!?!
}

The code is more complex but the idea is this.
it is possible?
what do you think?
Thankyou in advance,
Mario.
May 2 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 2, 4:17 pm, "_mario.lat" <n...@libero.itwrote:
Hallo,
I use a class vith a vaiables.
When a function throws an exception it seems to loose data:

...
$c=new myclass();
try{
$a->var1=1;
$a->function_throw_exception(); <--- this throws an exception
...}

catche(exception $e)
{
$a->var1; <--- is empty ?!?!

}

The code is more complex but the idea is this.
it is possible?
what do you think?
Thankyou in advance,
Mario.
When I run th following code it works as expected, echo'ing "baz":

class Foo {
public $x;

public function bar() {
throw new Exception();
}
}

$f = new Foo();

try {
$f->x = 'baz';
$f->bar(); //this throws an exception
} catch (Exception $e) {
echo $f->x; //this correctly prints "baz"
}

May 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.