简体   繁体   中英

need help catch a formatexception error

My workaround solution seems silly but it prevents the error. Is there a better way to do this?

try 
{
myNumber =  Convert.ToInt32(InputRow.Substring(288, 9));  
}
catch (FormatException e)
{
}

int.TryParse could be a good choice

int val = 0;
if(int.TryParse(InputRow.Substring(288, 9), out val))
   // insert val into db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM