1 Reply Latest reply on Nov 17, 2009 3:26 PM by Flex harUI

    Try catch question

    flexchief Level 1

      Hi,

       

      I've got a a problem with one of my methods called addToTop50(). Basically it's giving me a an error saying "TypeError: Error #1010: A term is undefined and has no properties" because one of the values i'm trying to add to a db table are not all present.

       

      I need to know if by adding the try catch blocks as shown in the attached code, should this solve my problem and allow the code to run without throwing an error and pausing the application as the debuger does?

       

       

      private function addToTop50():void
      {
             // Add the track to Top50 & AllPlayedTracks db tables
                
           if(thumbnailTileListItemClicked == true)
           {
                listTileListItemClicked = false;
                coverflowClicked = false;
                albumTrackClicked = false;
                searchFlowItemClicked = false;
                recommendedFlowItemClicked = false;
                
                try
                {
                     if(currentGenre[thumbnailTilelist.selectedIndex].trackPath != null && currentGenre[thumbnailTilelist.selectedIndex].imagePath != null && currentGenre[thumbnailTilelist.selectedIndex].artistName != null && currentGenre[thumbnailTilelist.selectedIndex].trackName != null && currentGenre[thumbnailTilelist.selectedIndex].albumName != null && nowViewingLabel.text != null && dayOfTheWeek != null)
                     {
                          insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[thumbnailTilelist.selectedIndex].trackPath + "\", \"" + currentGenre[thumbnailTilelist.selectedIndex].imagePath + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].artistName + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].trackName + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")";                              
                          insertIntoAllPlayedDBStatemement.execute();
                          
                          insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + currentGenre[thumbnailTilelist.selectedIndex].trackPath + "\", \"" + currentGenre[thumbnailTilelist.selectedIndex].imagePath + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].artistName + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].trackName + "\",\"" + currentGenre[thumbnailTilelist.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\")";
                          insertIntoTop50DBStatemement.execute();           
                     }               
                }
                catch(error:Error)
                {
                     trace("<Error> " + error.message);
                }
           }
           
           else if(listTileListItemClicked == true)
           {
                thumbnailTileListItemClicked = false;
                coverflowClicked = false;
                albumTrackClicked = false;
                searchFlowItemClicked = false;
                recommendedFlowItemClicked = false;
                try
                {
                     if(currentGenre[listTilelist.selectedIndex].trackPath != null && currentGenre[listTilelist.selectedIndex].imagePath != null && currentGenre[listTilelist.selectedIndex].artistName != null && currentGenre[listTilelist.selectedIndex].trackName != null && currentGenre[listTilelist.selectedIndex].albumName != null && nowViewingLabel.text != null && dayOfTheWeek != null)
                     {                              
                          insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                          //Problem found here with the below line....
                          insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[listTilelist.selectedIndex].trackPath + "\", \"" + currentGenre[listTilelist.selectedIndex].imagePath + "\",\"" + currentGenre[listTilelist.selectedIndex].artistName + "\",\"" + currentGenre[listTilelist.selectedIndex].trackName + "\",\"" + currentGenre[listTilelist.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")";
                          //Alert.show("INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[listTilelist.selectedIndex].trackPath + "\", \"" + currentGenre[listTilelist.selectedIndex].imagePath + "\",\"" + currentGenre[listTilelist.selectedIndex].artistName + "\",\"" + currentGenre[listTilelist.selectedIndex].trackName + "\",\"" + currentGenre[listTilelist.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")");
                          insertIntoAllPlayedDBStatemement.execute(); 
                          
                          insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + currentGenre[listTilelist.selectedIndex].trackPath + "\", \"" + currentGenre[listTilelist.selectedIndex].imagePath + "\",\"" + currentGenre[listTilelist.selectedIndex].artistName + "\",\"" + currentGenre[listTilelist.selectedIndex].trackName + "\",\"" + currentGenre[listTilelist.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\")";
                          insertIntoTop50DBStatemement.execute();
                     }                
                }
                catch(error:Error)
                {
                     trace("<Error> " + error.message);
                }
           }
           
           else if(coverflowClicked == true)
           {
                listTileListItemClicked = false;
                thumbnailTileListItemClicked = false;
                albumTrackClicked = false;
                searchFlowItemClicked = false;
                recommendedFlowItemClicked = false;
                          
                if(flowCurrentPage == 1)
                {
                     try
                     {
                          if(currentGenre[flow.selectedIndex].trackPath != null && currentGenre[flow.selectedIndex].imagePath != null && currentGenre[flow.selectedIndex].artistName != null && currentGenre[flow.selectedIndex].trackName != null && currentGenre[flow.selectedIndex].albumName != null && nowViewingLabel.text != null && dayOfTheWeek != null)
                          {
                               insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                               insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[flow.selectedIndex].trackPath + "\", \"" + currentGenre[flow.selectedIndex].imagePath + "\",\"" + currentGenre[flow.selectedIndex].artistName + "\",\"" + currentGenre[flow.selectedIndex].trackName + "\",\"" + currentGenre[flow.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")";
                               insertIntoAllPlayedDBStatemement.execute(); 
                               
                               insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                               insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + currentGenre[flow.selectedIndex].trackPath + "\", \"" + currentGenre[flow.selectedIndex].imagePath + "\",\"" + currentGenre[flow.selectedIndex].artistName + "\",\"" + currentGenre[flow.selectedIndex].trackName + "\",\"" + currentGenre[flow.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\")";
                               insertIntoTop50DBStatemement.execute();                    
                          }                    
                     }
                     catch(error:Error)
                     {
                          trace("<Error> " + error.message);
                     }          
                }
                else
                {
                     try
                     {
                          if(currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackPath != null && currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].imagePath != null && currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].artistName != null && currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackName != null && currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].albumName != null && nowViewingLabel.text != null && dayOfTheWeek != null)
                          {
                               insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                               insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackPath + "\", \"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].imagePath + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].artistName + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackName + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")";
                               insertIntoAllPlayedDBStatemement.execute(); 
                               
                               insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                               insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackPath + "\", \"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].imagePath + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].artistName + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].trackName + "\",\"" + currentGenre[(flow.selectedIndex + ((flowCurrentPage - 1) * maxPics))].albumName + "\", \"" + nowViewingLabel.text + "\")";
                               insertIntoTop50DBStatemement.execute();                    
                          }                     
                     }
                     catch(error:Error)
                     {
                          trace("<Error> " + error.message);
                     }               
                }          
           }
      
           else if(albumTrackClicked == true)
           {
                listTileListItemClicked = false;
                coverflowClicked = false;
                thumbnailTileListItemClicked = false;
                searchFlowItemClicked = false;
                recommendedFlowItemClicked = false;
                
                try
                {
                     if(currentGenre[albumTracksDatagrid.selectedIndex].trackPath != null && currentGenre[albumTracksDatagrid.selectedIndex].imagePath != null && currentGenre[albumTracksDatagrid.selectedIndex].artistName != null && currentGenre[albumTracksDatagrid.selectedIndex].trackName != null && currentGenre[albumTracksDatagrid.selectedIndex].albumName != null && nowViewingLabel.text != null && dayOfTheWeek != null)
                     {
                          insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + currentGenre[albumTracksDatagrid.selectedIndex].trackPath + "\", \"" + currentGenre[albumTracksDatagrid.selectedIndex].imagePath + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].artistName + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].trackName + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\", \"" + dayOfTheWeek + "\")";
                          insertIntoAllPlayedDBStatemement.execute(); 
                
                          insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + currentGenre[albumTracksDatagrid.selectedIndex].trackPath + "\", \"" + currentGenre[albumTracksDatagrid.selectedIndex].imagePath + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].artistName + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].trackName + "\",\"" + currentGenre[albumTracksDatagrid.selectedIndex].albumName + "\", \"" + nowViewingLabel.text + "\")";
                          insertIntoTop50DBStatemement.execute();                
                     }               
                }
                catch(error:Error)
                {
                     trace("<Error> " + error.message);
                }               
           }
           
           else if(searchFlowItemClicked == true)
           {
                listTileListItemClicked = false;
                coverflowClicked = false;
                albumTrackClicked = false;
                thumbnailTileListItemClicked = false;
                recommendedFlowItemClicked = false;
                
                try
                {
                     if(searchTrackData[searchFlow.selectedIndex].trackPath != null && searchTrackData[searchFlow.selectedIndex].imagePath != null && searchTrackData[searchFlow.selectedIndex].artistName != null && searchTrackData[searchFlow.selectedIndex].trackName != null && searchTrackData[searchFlow.selectedIndex].albumName != null && searchTextInput.text != null && dayOfTheWeek != null)
                     {
                          insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + searchTrackData[searchFlow.selectedIndex].trackPath + "\", \"" + searchTrackData[searchFlow.selectedIndex].imagePath + "\",\"" + searchTrackData[searchFlow.selectedIndex].artistName + "\",\"" + searchTrackData[searchFlow.selectedIndex].trackName + "\",\"" + searchTrackData[searchFlow.selectedIndex].albumName + "\", \"search term = " + searchTextInput.text + "\", \"" + dayOfTheWeek + "\")";
                          insertIntoAllPlayedDBStatemement.execute(); 
                          
                          insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                          insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + searchTrackData[searchFlow.selectedIndex].trackPath + "\", \"" + searchTrackData[searchFlow.selectedIndex].imagePath + "\",\"" + searchTrackData[searchFlow.selectedIndex].artistName + "\",\"" + searchTrackData[searchFlow.selectedIndex].trackName + "\",\"" + searchTrackData[searchFlow.selectedIndex].albumName + "\", \"search term = " + searchTextInput.text + "\")";
                          insertIntoTop50DBStatemement.execute();               
                     }               
                }
                catch(error:Error)
                {
                     trace("<Error> " + error.message);
                }
           }
           
           else if(recommendedFlowItemClicked == true)
           {
                listTileListItemClicked = false;
                coverflowClicked = false;
                albumTrackClicked = false;
                thumbnailTileListItemClicked = false;
                searchFlowItemClicked = false;
                /*
                insertIntoAllPlayedDBStatemement.sqlConnection = jukeDBConnection;
                insertIntoAllPlayedDBStatemement.text = "INSERT INTO All_Played_Tracks(trackPath, imagePath, artistName, trackName, albumName, genre, dayPlayed) VALUES (\"" + searchTrackData[recommendedFlow.selectedIndex].trackPath + "\", \"" + searchTrackData[recommendedFlow.selectedIndex].imagePath + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].artistName + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].trackName + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].albumName + "\", \"search term = " + "Now Playing/Recommended" + "\", \"" + dayOfTheWeek + "\")";
                insertIntoAllPlayedDBStatemement.execute(); 
                
                insertIntoTop50DBStatemement.sqlConnection = jukeDBConnection;
                insertIntoTop50DBStatemement.text = "INSERT INTO Top50(trackPath, imagePath, artistName, trackName, albumName, genre) VALUES (\"" + searchTrackData[recommendedFlow.selectedIndex].trackPath + "\", \"" + searchTrackData[recommendedFlow.selectedIndex].imagePath + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].artistName + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].trackName + "\",\"" + searchTrackData[recommendedFlow.selectedIndex].albumName + "\", \"search term = " + "Now Playing/Recommended" + "\")";
                insertIntoTop50DBStatemement.execute();     
                */
           }
      }
      

       

       

       

       

      Thanks

      Flexchief