הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   [PHP] בעיה עם throw ו catch (https://hosts.co.il/forums/showthread.php?t=50578)

WebProject 24-07-07 22:02

[PHP] בעיה עם throw ו catch
 
אני לא חושב שיש פה הרבה שמשתמשים בPHP5, אבל לאלו שכן:
יש לי פה שגיאה מוזרה, ניסיתי מספר פיתרונות לבעיה אבל אני לא מצליח לסדר את זה.

הצבתי בConstructor בדיקה של אם זה טמפלייט של פורום, ואם כן שיתן שגיאה, בדיקה פשוטה, ועדיין מתקבלת על כך שגיאה.

PHP קוד:

<?Php 
##@ 
##@         
##@
        
    
class TemplatesError extends Exception
    
{
        function 
__construct()
        {

        }
    }
    class 
LoadingError extends TemplatesError
    
{
        function 
__construct()
        {
            
Exception::__construct("Loading Error: Template Does Not Exists.",2);
        }
    } 
    class 
GetTemplate
    
{
            private 
$path '../templates';
             
            function 
__construct($toLoad
            {
                global 
$DB;
 
                    if(
$toLoad == 'forum'
                    {
                        throw new 
LoadingError();
                    } 

                              
            } 
    }

    try 
     { 
          
     } 
     catch(
TemplatesError $err
     { 
         echo 
$err->getMessage(); 
     }
 
    
$template = new GetTemplate($toLoad); 
?>

אני מקבל את השגיאה הבאה:

ציטוט:


Fatal error: Uncaught exception 'LoadingError' with message 'Loading Error: Template Does Not Exists.' in /home/webproject/Desktop/sites/PageMaker/templates/GetTemp.php:30 Stack trace: #0 /home/webproject/Desktop/sites/PageMaker/templates/GetTemp.php(46): GetTemplate->__construct('forum') #1 /home/webproject/Desktop/sites/PageMaker/forum/index.php(14): include('/home/webprojec...') #2 {main} thrown in /home/webproject/Desktop/sites/PageMaker/templates/GetTemp.php on line 30

ניסיתי מספר דרכים לפתור את השגיאה אבל לא הצלחתי :S


-טל

בניה 24-07-07 22:06

PHP קוד:

$template = new GetTemplate($toLoad); 

זה לא אמור להיות בתוך ה TRY?

WebProject 24-07-07 22:12

ציטוט:

נכתב במקור על ידי בניה (פרסם 528876)
PHP קוד:

$template = new GetTemplate($toLoad); 

זה לא אמור להיות בתוך ה TRY?

טעות קטנה שלי, אבל בכל מקרה אותה שגיאה.

WebProject 24-07-07 22:15

ציטוט:

נכתב במקור על ידי WebProject (פרסם 528883)
טעות קטנה שלי, אבל בכל מקרה אותה שגיאה.

עריכה:

אפשר לנעול, הבעיה לא הייתה בקובץ הזה :)

Level-Serv 24-07-07 22:30

ננעל.

פעם הבאה תערוך את ההודעה שלך ואל תעשה דאבל פוסט.


כל הזמנים הם GMT +2. הזמן כעת הוא 13:10.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ