exception for filling matrix in C# -


i have code block below, when i'm filling matrix , if put enter or space instead of numbers mistake, program stop, know needs add exception don't know or how add trycatch in code or should write in body of trycatch code:

int row = 0; int col = 0; int[ , ] matrix1;  row = convert.toint16( console.readline( ) ); col = convert.toint16( console.readline( ) ); matrix1 = new int[ row, col ]; console.writeline( "enter numbers" ); ( int = 0; < row; i++ )    {      ( int j = 0; j < col; j++ )       {         matrix1[ i, j ] = convert.toint16( console.readline( ) );        }    } 

if want display message , exit can use

int row = 0; int col = 0; int[ , ] matrix1;  int row = 0; int col = 0; int[ , ] matrix1;  row = convert.toint16( console.readline( ) ); col = convert.toint16( console.readline( ) ); matrix1 = new int[ row, col ]; console.writeline( "enter numbers" ); try {  ( int = 0; < row; i++ ) {     ( int j = 0; j < col; j++ )     {     matrix1[ i, j ] = convert.toint16( console.readline( ) );    } }  }   catch(exception e)  {   console.writeline("you have entered invalid character");   } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -