PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > What is the difference between exceptions and simple error handlingtechniques?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
What is the difference between exceptions and simple error handlingtechniques?

Réponse
 
LinkBack Outils de la discussion
Vieux 03/12/2007, 03h56   #1
adam.timberlake@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut What is the difference between exceptions and simple error handlingtechniques?

I've just finished reading the article below which goes into some
depth about exceptions. The article was rather lucid and so I
understand how to implement it all, the thing I'm having trouble with
though is why would I need to them? For example, I could suppress my
functions using the @ sign and then use an if statement to check if
they returned false or not. Similarly, I can also return various
integers, like -4 and -5 for errors, and check those.

Article: http://www.talkphp.com/showthread.php?t=1478

As you can see, the article gives some reasons why, but I don't think
it's quite convinced me that exceptions are the way to go. I thought
maybe they'd introduce a lot more into the error handling side of
things, but I think I am mistaken. Unless I am overlooking something?
  Réponse avec citation
Vieux 03/12/2007, 04h42   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What is the difference between exceptions and simple error handlingtechniques?

adam.timberlake@gmail.com wrote:
> I've just finished reading the article below which goes into some
> depth about exceptions. The article was rather lucid and so I
> understand how to implement it all, the thing I'm having trouble with
> though is why would I need to them? For example, I could suppress my
> functions using the @ sign and then use an if statement to check if
> they returned false or not. Similarly, I can also return various
> integers, like -4 and -5 for errors, and check those.
>
> Article: http://www.talkphp.com/showthread.php?t=1478
>
> As you can see, the article gives some reasons why, but I don't think
> it's quite convinced me that exceptions are the way to go. I thought
> maybe they'd introduce a lot more into the error handling side of
> things, but I think I am mistaken. Unless I am overlooking something?
>


Exceptions have the advantage you don't have to keep checking return
values. They allow you to handle the error where handling makes the
most sense, instead of where the error occurs.

Without them, you need to test the return code from every function call,
and if you can't handle it here, return another bad return code to your
caller. And so on back.

Additionally, if you call multiple functions and need them all to work,
you end up with a maze of if/else statements. You don't need them with
exceptions; just put everything within a try block; if it all works,
fine. If not, the appropriate catch block will be called for you.

For simple scripts, exceptions probably aren't needed. But as your
scripts get more complicated, exceptions become more useful.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10478 seconds with 10 queries