Skip to content
Permalink
Browse files
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
  • Loading branch information
wonder-sk committed Jun 27, 2014
1 parent 2575dca commit f9d9c2a43cca78ec8544d0b0eacd5d9830169f28
Showing with 59 additions and 6 deletions.
  1. +9 −3 src/core/qgsapplication.cpp
  2. +16 −1 src/core/qgsmaprenderercustompainterjob.cpp
  3. +34 −2 src/core/qgsmaprendererparalleljob.cpp
@@ -244,15 +244,21 @@ bool QgsApplication::notify( QObject * receiver, QEvent * event )
}
catch ( QgsException & e )
{
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
if ( qApp->thread() == QThread::currentThread() )
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
}
catch ( std::exception & e )
{
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
if ( qApp->thread() == QThread::currentThread() )
QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
}
catch ( ... )
{
QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
QgsDebugMsg( "Caught unhandled unknown exception" );
if ( qApp->thread() == QThread::currentThread() )
QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
}

return done;
@@ -187,7 +187,22 @@ void QgsMapRendererCustomPainterJob::futureFinished()

void QgsMapRendererCustomPainterJob::staticRender( QgsMapRendererCustomPainterJob* self )
{
self->doRender();
try
{
self->doRender();
}
catch ( QgsException & e )
{
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
}
catch ( std::exception & e )
{
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
}
catch ( ... )
{
QgsDebugMsg( "Caught unhandled unknown exception" );
}
}

void QgsMapRendererCustomPainterJob::doRender()
@@ -207,7 +207,24 @@ void QgsMapRendererParallelJob::renderLayerStatic( LayerRenderJob& job )
QTime t;
t.start();
QgsDebugMsg( QString( "job %1 start" ).arg(( ulong ) &job, 0, 16 ) );
job.renderer->render();

try
{
job.renderer->render();
}
catch ( QgsException & e )
{
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
}
catch ( std::exception & e )
{
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
}
catch ( ... )
{
QgsDebugMsg( "Caught unhandled unknown exception" );
}

int tt = t.elapsed();
QgsDebugMsg( QString( "job %1 end [%2 ms]" ).arg(( ulong ) &job, 0, 16 ).arg( tt ) );
Q_UNUSED( tt );
@@ -218,7 +235,22 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob* s
{
QPainter painter( &self->mFinalImage );

drawLabeling( self->mSettings, self->mLabelingRenderContext, self->mLabelingEngine, &painter );
try
{
drawLabeling( self->mSettings, self->mLabelingRenderContext, self->mLabelingEngine, &painter );
}
catch ( QgsException & e )
{
QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
}
catch ( std::exception & e )
{
QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
}
catch ( ... )
{
QgsDebugMsg( "Caught unhandled unknown exception" );
}

painter.end();
}

0 comments on commit f9d9c2a

Please sign in to comment.