diff --git a/inputsource.cpp b/inputsource.cpp index 64f7193..bccaf21 100644 --- a/inputsource.cpp +++ b/inputsource.cpp @@ -12,15 +12,17 @@ InputSource::InputSource(const char *filename, int fft_size) { m_fft_size = fft_size; m_file = fopen(filename, "rb"); - // TODO: throw exception if failed + if (m_file == nullptr) + throw "Error opening file"; struct stat sb; - fstat(fileno(m_file), &sb); - // TODO: throw exception if failed + if (fstat(fileno(m_file), &sb) != 0) + throw "Error fstating file"; m_file_size = sb.st_size; m_data = (fftwf_complex*)mmap(NULL, m_file_size, PROT_READ, MAP_SHARED, fileno(m_file), 0); - // TODO: throw exception if failed + if (m_data == 0) + throw "Error mmapping file"; m_fftw_in = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * m_fft_size); m_fftw_out = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * m_fft_size); diff --git a/main.cpp b/main.cpp index 9525b58..8a60a52 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,8 @@ class MyApp: public wxApp { +private: + InputSource *m_input_source; public: virtual bool OnInit(); }; @@ -49,9 +51,14 @@ bool MyApp::OnInit() fft_size = size; } - InputSource *is = new InputSource(argv[1], fft_size); + try { + m_input_source = new InputSource(argv[1], fft_size); + } catch (const char *msg) { + printf("%s\n", msg); + return false; + } - wxImagePanel *impanel = new wxImagePanel(frame, is); + wxImagePanel *impanel = new wxImagePanel(frame, m_input_source); sizer->Add(impanel, 1, wxALL | wxEXPAND, 0); frame->SetSizer(sizer);