Skip to content

Commit

Permalink
Improve exception handling
Browse files Browse the repository at this point in the history
- 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 f9d9c2a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/core/qgsapplication.cpp
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion src/core/qgsmaprenderercustompainterjob.cpp
Expand Up @@ -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()
Expand Down
36 changes: 34 additions & 2 deletions src/core/qgsmaprendererparalleljob.cpp
Expand Up @@ -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 );
Expand All @@ -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();
}
Expand Down

0 comments on commit f9d9c2a

Please sign in to comment.