| 1 | package tuffy.util; |
| 2 | |
| 3 | import java.io.File; |
| 4 | |
| 5 | import tuffy.db.RDB; |
| 6 | |
| 7 | |
| 8 | /** |
| 9 | * Container of exception related utilities. |
| 10 | */ |
| 11 | public class ExceptionMan { |
| 12 | public static void handle(Exception e) { |
| 13 | if(Config.exiting_mode) return; |
| 14 | e.printStackTrace(System.err); |
| 15 | die(e.getMessage()); |
| 16 | } |
| 17 | |
| 18 | public static void die(String msg){ |
| 19 | if(Config.exiting_mode) return; |
| 20 | Config.exiting_mode = true; |
| 21 | UIMan.error(msg); |
| 22 | RDB db = RDB.getRDBbyConfig(); |
| 23 | |
| 24 | if(Config.keep_db_data == false){ |
| 25 | UIMan.print("removing database schema '" + Config.db_schema + "'..."); |
| 26 | UIMan.println(db.dropSchema(Config.db_schema)?"OK" : "FAILED"); |
| 27 | } |
| 28 | |
| 29 | UIMan.print("removing temporary dir '" + Config.getWorkingDir() + "'..."); |
| 30 | UIMan.println(FileMan.removeDirectory(new File(Config.getWorkingDir()))?"OK" : "FAILED"); |
| 31 | if(Config.throw_exception_when_dying){ |
| 32 | throw new TuffyThrownError(msg); |
| 33 | }else{ |
| 34 | System.exit(2); |
| 35 | } |
| 36 | } |
| 37 | } |