1、优化了异常处理

This commit is contained in:
2025-05-12 11:25:42 +08:00
parent c027992c0e
commit 9c838ff3ad
7 changed files with 109 additions and 104 deletions

View File

@ -1,5 +1,6 @@
from gc import collect
from pathlib import Path
from traceback import format_exc
import matplotlib.pyplot as plt
from PySide6.QtCore import QTimer, QCoreApplication
@ -387,8 +388,8 @@ class MainWindow_label_check(QMainWindow):
self.ax1.callbacks.connect('xlim_changed', lambda ax: self.on_xlim_change(ax))
self.ax0.legend(loc=Constants.PLOT_UPPER_RIGHT)
self.ax1.legend(loc=Constants.PLOT_UPPER_RIGHT)
except Exception:
return Result().failure(info=Constants.DRAWING_FAILURE)
except Exception as e:
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
self.canvas.draw()
return Result().success(info=Constants.DRAWING_FINISHED)
@ -415,8 +416,8 @@ class MainWindow_label_check(QMainWindow):
item = QTableWidgetItem(str(value).strip())
self.ui.tableWidget_peak_corrected.setItem(row, 0, item)
return Result().success(info=Constants.UPDATING_FINISHED)
except Exception:
return Result().failure(info=Constants.UPDATING_FAILURE)
except Exception as e:
return Result().failure(info=Constants.UPDATING_FAILURE + "\n" + format_exc())
def __update_config__(self):
Config["FindPeaks"]["MinInterval"] = self.ui.doubleSpinBox_findpeaks_min_interval.value()
@ -898,8 +899,8 @@ class Data:
self.original_peak = read_csv(Config["Path"]["Input_Peak"],
encoding=ConfigParams.UTF8_ENCODING,
header=None).to_numpy().reshape(-1)
except Exception:
return Result().failure(info=Constants.INPUT_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Read_Data_Exception"])
except Exception as e:
return Result().failure(info=Constants.INPUT_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Read_Data_Exception"] + "\n" + format_exc())
try:
df = read_csv(Config["Path"]["Input_Approximately_Align"])
@ -952,8 +953,8 @@ class Data:
raise ValueError("模式不存在")
self.original_peak_y = [self.processed_data[x] for x in self.original_peak]
self.corrected_peak_y = [self.processed_data[x] for x in self.corrected_peak]
except Exception:
return Result().failure(info=Constants.LABEL_CHECK_PROCESS_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Filter_Exception"])
except Exception as e:
return Result().failure(info=Constants.LABEL_CHECK_PROCESS_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Filter_Exception"] + "\n" + format_exc())
return Result().success(info=Constants.LABEL_CHECK_PROCESS_FINISHED)
@ -963,8 +964,8 @@ class Data:
try:
chunk.to_csv(Config["Path"]["Save"], mode='a', index=False, header=False)
except Exception:
return Result().failure(info=Constants.SAVING_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Save_Exception"])
except Exception as e:
return Result().failure(info=Constants.SAVING_FAILURE + Constants.LABEL_CHECK_FAILURE_REASON["Save_Exception"] + "\n" + format_exc())
return Result().success(info=Constants.SAVING_FINISHED)