IndianaJoe Posted June 29, 2021 Share Posted June 29, 2021 Right now I have some queries in a block that will throw an error when it looks up a record and it has been deleted. This screws up the whole page instead of just skipping the record. Is there a way to check the table for the record before doing this in order to skip the record? Here is my code {{$wDB = \IPS\Db::i()->select( 'field_48, field_51, field_59, field_52, field_450, field_522', 'cms_custom_database_9', array( 'primary_id_field=?', $wID) )->first();}} I know that the error I receive is for past entries where I deleted records that it is looking for. Any help on how to not throw an error and just go on it's merry way would be appreciated. Link to comment Share on other sites More sharing options...
Sonya* Posted June 29, 2021 Share Posted June 29, 2021 Use try/catch for your query: {{try{ $wDB = \IPS\Db::i()->select( 'field_48, field_51, field_59, field_52, field_450, field_522', 'cms_custom_database_9', array( 'primary_id_field=?', $wID) )->first();}catch( \UnderflowException $e ){ $wDB = NULL; } }} {{if $wDB}} Record was found, do something with it. {{endif}} IndianaJoe 1 Link to comment Share on other sites More sharing options...
IndianaJoe Posted June 29, 2021 Author Share Posted June 29, 2021 Thanks @Sonya*, that worked! I wasn't sure how to utilize the try/catch within the code. Link to comment Share on other sites More sharing options...
Recommended Posts