Program doesn't stop after exception

后端 未结 6 792
悲哀的现实
悲哀的现实 2021-01-21 03:11

I am using eclipse in Ubuntu 12.04. I use some exceptions in my program and when they are caught it gives me cout correctly. But the program continues to the end. Is there a way

6条回答
  •  粉色の甜心
    2021-01-21 04:07

    Some solutions:

    1. use return from your function (and do that accordingly to your return value) if you're doing this in the main() routine

    2. use exit(n) where n is the exit code (http://www.cplusplus.com/reference/cstdlib/exit/)

    3. abort() if that's a critical issue (http://www.cplusplus.com/reference/cstdlib/abort/)

    Notice: as noted by James Kanze, exit and abort will NOT call the destructors of your local objects. This is worth noticing since you're dealing with classes.

提交回复
热议问题