@@ -341,14 +341,21 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
341341 }
342342 }
343343
344-
345344
346- var spectrum = ConstructMSSpectrum ( scanNumber ) ;
345+ SpectrumType spectrum = null ;
347346
348- var level = int . Parse ( spectrum . cvParam . Where ( p => p . accession == "MS:1000511" ) . First ( ) . value ) ;
349-
350-
347+ try
348+ {
349+ spectrum = ConstructMSSpectrum ( scanNumber ) ;
350+ }
351+ catch ( Exception ex )
352+ {
353+ Log . Error ( $ "Scan #{ scanNumber } cannot be processed because of the following exception: { ex . Message } \n { ex . StackTrace } ") ;
354+ ParseInput . NewError ( ) ;
355+ }
351356
357+ var level = spectrum != null ? int . Parse ( spectrum . cvParam . Where ( p => p . accession == "MS:1000511" ) . First ( ) . value ) : 0 ;
358+
352359 if ( spectrum != null && ParseInput . MsLevel . Contains ( level ) ) //applying MS level filter
353360 {
354361 spectrum . index = index . ToString ( ) ;
@@ -409,7 +416,18 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
409416 }
410417 }
411418
412- var spectrum = ConstructPDASpectrum ( scanNumber , nrI ) ;
419+ SpectrumType spectrum = null ;
420+
421+ try
422+ {
423+ spectrum = ConstructPDASpectrum ( scanNumber , nrI ) ;
424+ }
425+ catch ( Exception ex )
426+ {
427+ Log . Error ( $ "Scan #{ scanNumber } cannot be processed because of the following exception: { ex . Message } \n { ex . StackTrace } ") ;
428+ ParseInput . NewError ( ) ;
429+ }
430+
413431 if ( spectrum != null )
414432 {
415433 spectrum . index = index . ToString ( ) ;
@@ -1312,13 +1330,25 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
13121330
13131331 if ( _precursorScanNumber > 0 )
13141332 {
1315- // Construct and set the precursor list element of the spectrum
1316- spectrum . precursorList =
1317- ConstructPrecursorList ( _precursorScanNumber , scanEvent , charge , monoisotopicMz , isolationWidth ,
1318- SPSMasses , out var reactionCount ) ;
1333+
1334+ try
1335+ {
1336+ // Construct and set the precursor list element of the spectrum
1337+ spectrum . precursorList =
1338+ ConstructPrecursorList ( _precursorScanNumber , scanEvent , charge , monoisotopicMz , isolationWidth ,
1339+ SPSMasses , out var reactionCount ) ;
13191340
1320- //save precursor information for later reference
1321- _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , reactionCount , spectrum . precursorList . precursor ) ;
1341+ //save precursor information for later reference
1342+ _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , reactionCount , spectrum . precursorList . precursor ) ;
1343+ }
1344+ catch ( RawFileParserException e )
1345+ {
1346+ Log . Warn ( $ "Failed creating precursor list for scan# { scanNumber } ; { e . Message } ; precursor information for this and dependent scans will be empty") ;
1347+ ParseInput . NewWarn ( ) ;
1348+
1349+ _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , 0 , new PrecursorType [ 0 ] ) ;
1350+ }
1351+
13221352 }
13231353 else
13241354 {
@@ -2133,8 +2163,7 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
21332163 }
21342164 catch ( ArgumentOutOfRangeException )
21352165 {
2136- Log . Warn ( $ "Failed to get reaction when parsing precursor { precursorScanNumber } ") ;
2137- ParseInput . NewWarn ( ) ;
2166+ throw new RawFileParserException ( $ "Cannot get reaction at index { reactionCount } from { scanEvent . ToString ( ) } ") ;
21382167 }
21392168
21402169 var precursor = new PrecursorType
0 commit comments