CBrother运行时出现了异常,会直接将抛出,停止当前线程工作。如果开发者没有主动捕获异常,则会被CBrother解释器最终捕获并输出。trycatch CBrother通过trycatch来主动捕获异常functionmain(parm){try{printc;}catch(e){printe;}printmainend!;} 结果:NotFindException:cantfindcatmain〔testtrycatch。cb:7〕mainend! 可见错误被捕获后程序继续执行,打印出了mainend! catch中的参数是字符串类型的异常信息。finally finally表示无论是否发生异常,finally中的代码都将被执行。functionmain(parm){try{print1;}catch(e){printe;}finally{printinexceptfinallynoexception;}print;try{printc;}catch(e){printe;}finally{printinexceptfinallyexception;}printmainend!;} 结果:1inexceptfinallynoexceptionNotFindException:cantfindcatmain〔testtrycatch。cb:22〕inexceptfinallyexceptionmainend! finally中的代码,即便是在return之后也会被执行functionmain(parm){try{return1;}catch(e){printe;}finally{printinexceptfinallynoexception;}printmainend!;} 结果:inexceptfinallynoexception 出现异常时functionmain(parm){try{printc;}catch(e){printe;return1;}finally{printinexceptfinallyexception;}printmainend!;} 结果:NotFindException:cantfindcatmain〔testtrycatch。cb:7〕inexceptfinallyexception 因为return了,mainend!不会打印出来,但是finally执行了捕获到异常时,如果catch或finally中的代码再次出现异常,则无法再次在当前函数捕获,会直接将异常抛到函数调用堆栈的上一层等待处理。