Current location: Hot Scripts Forums » General Web Coding » Flash & ActionScript » [SOLVED] I don't see the fault


[SOLVED] I don't see the fault

Reply
  #11 (permalink)  
Old 02-29-08, 04:55 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Exceptions were introduced in PHP5. It is similar to errors, but you can catch them and prevent your code from being interrupted by creating a b-way.

Let me explain it with an example: let's say you have a function that checks if a given fruit is an apple. If it is so, it shouts "I'm an apple", if it isn't, it throws an Exception saying an invalid fruit was found. Suppose only apples and oranges are present in your data-set, so you know it has to be an orange. What you can do is the following:
PHP Code:

function amIAnAplle ($var) {
  if (
$var == "apple")
    echo 
"I'M AN APPLE!!";
  else
    throw new 
Exception ("invalid fruit found");
}

function 
iAmAnOrange ($var) {
  echo 
"I'm nothing but an orange";
}

$var "orange";

try {
  
amIAnApple ($var);
} catch (
$e) {
  
iAmAnOrange ($var);

The code above would output "I'm nothing but an orange", because the amIAnApple function threw an exception because it wasn't an apple. If $var would contain the value "apple", it would say "I'M AN APPLE".

Exceptions are usefull when you have several options to achieve your goal: you simply try one way, if it doesn't work, you try a different way, if that doesn't work, try another one and so on, till eventually some way works or you ran out of ways


As for your problem: can you tell us what the error message is?
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #12 (permalink)  
Old 02-29-08, 06:04 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
I've been searching, try-ing and stress-ing a lot on this issue..

finaly I fixed it! so there are no errors now. I took a lot of the code you gave me and deleted iit, because I didn't need it. Now what's left did the job for.

Thanx for helping me out and give me several things to look at. this made me come to a fix!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fault tolerance ornoc JavaScript 1 10-17-05 03:02 PM
Anybody know whats wrong NerdRUS PHP 3 01-01-04 11:11 PM


All times are GMT -5. The time now is 06:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.