← Back to team overview

kicad-developers team mailing list archive

Odd behaviour with try catch in pcb parser

 

Hi,

I am quite new to C++ and can not wrap my head around the issue I
encountered in the code below.

To give  a littel background:
I am currently adding information to the via list saved as user_via in the
kicad_pcb file.

Adding more values to the keyword causes the compatibility to break
backwards. Since the parser expects an closing parenthesis at the second
value and can not find it.

But also forwards, since old save files have two valuies and than the
clopsing parenthesis. I came to te conclusion to load up sensible default
data when loading old files is the way to go. So I tried this piece of code:

int viaSize = parseBoardUnits( "user via size" );
int viaDrill = parseBoardUnits( "user via drill" );
try
{
    VIATYPE_T viaType = (VIATYPE_T)parseInt( "user via type" );
    PCB_LAYER_ID viaStartLayer = (PCB_LAYER_ID)parseInt( "user via start" );
    PCB_LAYER_ID viaEndLayer = (PCB_LAYER_ID)parseInt( "user via end" );
    designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize,
viaDrill, viaType, viaStartLayer, viaEndLayer ) );
}
catch(const PARSE_ERROR& parse_error )
{
    designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize,
viaDrill, VIA_NOT_DEFINED, F_Cu, B_Cu ) );
}


Stepping through line by line leads me to the catch part of the block but
the error is shown and pcbnew closed nonetheless.
This is because it also propagetes down the call stack to the parseBOARD()
function where it end in the else part of the catch block

try
{
    return parseBOARD_unchecked(); // <- This parses the board file and
encounters the code above that should catch the PARSE_ERROR
}
catch( const PARSE_ERROR& parse_error )
{
    if( m_tooRecent )
        throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
    else
        throw; // we end here anyway
}

I thought having an exception caught does stop its propagation? So why does
it come anyway?

Cheers,
Basti