catch error (SOLVED!)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

catch error (SOLVED!)

Post by DelPazzo »

Hi,

How to catch this error:

Uncaught exception 'com_exception' with message '<b>Source:</b> ADODB.Field<br/><b>Description:</b> either BOF or EOF is True...

for this line:

Code: Select all

if (trim($a->value) !="") {
I tried:

Code: Select all

if (trim($a->value) !="") {
echo 'hallo';
} else {
die("<tr><td>Keine Rechnung vorgemerkt</td></tr>");
}
but it does not work.
Last edited by DelPazzo on Sat Jan 01, 2011 9:09 am, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: catch error

Post by social_experiment »

If there is an exception that has been thrown, it needs to be caught

Code: Select all

<?php
 try {
 // execute code
 }
 catch (Exception $e) {
 // display message
 }
?>
In your case it might be something to the nature of :

Code: Select all

<?php
 try {
  // 
  $a = new Classname
  if (trim($a->value) != "") {
   echo 'Hallo';
  } 
  else {
   // error message
  }
 }
 catch (Exception $e) {
  echo $e->getMessage();
 }
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: catch error

Post by DelPazzo »

that throws:

Class 'Classname' not found in

where you set: $a = new Classname
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: catch error

Post by social_experiment »

Yes it will because my code is an example. $a->value indicates to me an object is involved so you have to instantiate an object first, which is what the line $a = new Classname does. You should substitute it (Classname) for the name of your class.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: catch error

Post by DelPazzo »

social_experiment wrote:Yes it will because my code is an example. $a->value indicates to me an object is involved so you have to instantiate an object first, which is what the line $a = new Classname does. You should substitute it (Classname) for the name of your class.
sorry... me noob. how to find out which class it is? :(
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: catch error

Post by anantha »

you can try to use get_class()...see php website for the list of functions that can be used....
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: catch error

Post by social_experiment »

anantha wrote:you can try to use get_class()
I think this will only work if an object has been instantiated.

Code: Select all

<?php

class foo {
    function name()
    {
        echo "My name is " , get_class($this) , "\n";
    }
}

// create an object
$bar = new foo();

// external call
echo "Its name is " , get_class($bar) , "\n";

// internal call
$bar->name();

?>
Is there any additional code that you can paste?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: catch error

Post by DelPazzo »

this is the only code that comes before:

Code: Select all

$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
  $conn->open($connStr); //Open the connection to the database

$recordSet = &$conn->Execute('SELECT max(uebkunden.id) as id, translat.rechid, uebkunden.name FROM translat INNER JOIN uebkunden ON translat.kunde = uebkunden.id WHERE (translat.rechid <> 0) AND (translat.rechn = 1) AND (translat.druck = 0) group by uebkunden.id, uebkunden.name, translat.rechid order by rechid');

if (trim($a->value) !="") {
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: catch error

Post by social_experiment »

What happens if you modify the code like the sample below

Code: Select all

<?php
 //
 try {
 $recordSet = &$conn->Execute('SELECT max(uebkunden.id) as id, translat.rechid, uebkunden.name FROM translat INNER JOIN uebkunden ON translat.kunde = uebkunden.id WHERE (translat.rechid <> 0) AND (translat.rechn = 1) AND (translat.druck = 0) group by uebkunden.id, uebkunden.name, translat.rechid order by rechid');
  // rest of the code
 }
 catch (Exception $e) {
  echo $e->getMessage();
 }
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: catch error

Post by DelPazzo »

that works perfectly.... :D

thx a lot.

here is the complete code now working as it should:

Code: Select all

try {
         $recordSet = &$conn->Execute('SELECT max(uebkunden.id) as id, translat.rechid, uebkunden.name FROM translat INNER JOIN uebkunden ON translat.kunde = uebkunden.id WHERE (translat.rechid <> 0) AND (translat.rechn = 1) AND (translat.druck = 0) group by uebkunden.id, uebkunden.name, translat.rechid order by rechid');
         $a = $recordSet->fields['name'];
         if (trim($a->value) !="") {
                  echo '<tr><td><form name="marken" method="post"> ';
                  Echo ' <select size="1" name="kunde" onChange="document.marken.submit();">';
                  Echo ' <option value="">---Auswahl---</option> ';
                  while (!$recordSet->EOF) {
                         Echo ' <option value="'.$recordSet->fields['id'].'" ';
                         Echo ' >'.$recordSet->fields['name'].' '.$recordSet->fields['rechid'].'</option> ';
                         $recordSet->MoveNext();
                  }
         echo ' </select></td></tr>';
         }
}
catch (Exception $e) {
echo ' <tr><td>Keine Rechnung vorgemerkt</td></tr>';
}
Post Reply