一、PHP抛错
// 正确的抛出异常
try { if (file_exists('test_try_catch.php')) { require ('test_try_catch.php'); } else { throw new Exception('file is not exists');//throw扔出去,catch会抓到错误信息 } } catch (Exception $e) { echo $e->getMessage(); }
二、python抛错
try: result = data.query('(name=="&")and(age>=20)') print(result) except Exception as e://这行不动,原样写
print('Error:', e)
没有报错的时候输出:
id name age 4 5 & 20
报错的时候输出:
Error: invalid syntax (<unknown>, line 1)