Posted June 29, 20213 yr 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.
June 29, 20213 yr 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}}
June 29, 20213 yr Author Thanks @Sonya*, that worked! I wasn't sure how to utilize the try/catch within the code.