Skip to content

Commit f9d9c2a

Browse files
committed
Improve exception handling
- Do at least very basic handling in QtConcurrent run functions - Do not show a message box when not running in main thread
1 parent 2575dca commit f9d9c2a

3 files changed

+59
-6
lines changed

src/core/qgsapplication.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,21 @@ bool QgsApplication::notify( QObject * receiver, QEvent * event )
244244
}
245245
catch ( QgsException & e )
246246
{
247-
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
247+
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
248+
if ( qApp->thread() == QThread::currentThread() )
249+
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
248250
}
249251
catch ( std::exception & e )
250252
{
251-
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
253+
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
254+
if ( qApp->thread() == QThread::currentThread() )
255+
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
252256
}
253257
catch ( ... )
254258
{
255-
QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
259+
QgsDebugMsg( "Caught unhandled unknown exception" );
260+
if ( qApp->thread() == QThread::currentThread() )
261+
QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
256262
}
257263

258264
return done;

src/core/qgsmaprenderercustompainterjob.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,22 @@ void QgsMapRendererCustomPainterJob::futureFinished()
187187

188188
void QgsMapRendererCustomPainterJob::staticRender( QgsMapRendererCustomPainterJob* self )
189189
{
190-
self->doRender();
190+
try
191+
{
192+
self->doRender();
193+
}
194+
catch ( QgsException & e )
195+
{
196+
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
197+
}
198+
catch ( std::exception & e )
199+
{
200+
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
201+
}
202+
catch ( ... )
203+
{
204+
QgsDebugMsg( "Caught unhandled unknown exception" );
205+
}
191206
}
192207

193208
void QgsMapRendererCustomPainterJob::doRender()

src/core/qgsmaprendererparalleljob.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,24 @@ void QgsMapRendererParallelJob::renderLayerStatic( LayerRenderJob& job )
207207
QTime t;
208208
t.start();
209209
QgsDebugMsg( QString( "job %1 start" ).arg(( ulong ) &job, 0, 16 ) );
210-
job.renderer->render();
210+
211+
try
212+
{
213+
job.renderer->render();
214+
}
215+
catch ( QgsException & e )
216+
{
217+
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
218+
}
219+
catch ( std::exception & e )
220+
{
221+
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
222+
}
223+
catch ( ... )
224+
{
225+
QgsDebugMsg( "Caught unhandled unknown exception" );
226+
}
227+
211228
int tt = t.elapsed();
212229
QgsDebugMsg( QString( "job %1 end [%2 ms]" ).arg(( ulong ) &job, 0, 16 ).arg( tt ) );
213230
Q_UNUSED( tt );
@@ -218,7 +235,22 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob* s
218235
{
219236
QPainter painter( &self->mFinalImage );
220237

221-
drawLabeling( self->mSettings, self->mLabelingRenderContext, self->mLabelingEngine, &painter );
238+
try
239+
{
240+
drawLabeling( self->mSettings, self->mLabelingRenderContext, self->mLabelingEngine, &painter );
241+
}
242+
catch ( QgsException & e )
243+
{
244+
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
245+
}
246+
catch ( std::exception & e )
247+
{
248+
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
249+
}
250+
catch ( ... )
251+
{
252+
QgsDebugMsg( "Caught unhandled unknown exception" );
253+
}
222254

223255
painter.end();
224256
}

0 commit comments

Comments
 (0)