]> git.mxchange.org Git - jaddressbook-share-lib.git/commitdiff
More rewrites for thrown exceptions
authorRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 13:19:56 +0000 (15:19 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 13:32:56 +0000 (15:32 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java
Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java
Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableAddressbookContact.java

index e4ac7a9f6b15b3fb6d406cd4173d0d622a1feb86..4be3359bdbe5fb7c6a7cbb6d3d62d55fdaed979b 100644 (file)
@@ -338,6 +338,13 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App
         */
        private void start (final String args[]) {
                this.getLogger().info("Program is started."); //NOI18N
+               try {
+                       // Init properties file
+                       this.initProperties();
+               } catch (final IOException ex) {
+                       // Something bad happened
+                       this.abortProgramWithException(ex);
+               }
 
                // Parse arguments
                this.parseArguments(args);
index a94762045c126963ada0e4bc4524c7c924c1f4c8..6ed15fb2a04a79feee994d412fdfc53bbc388a1c 100644 (file)
@@ -35,6 +35,7 @@ import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem;
 import org.mxchange.jcore.application.Application;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 
@@ -342,41 +343,43 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                // Get manager and cast it
                ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
-               // @TODO Rewrite this ugly switch() block
-               switch (choice) {
-                       case '1':
-                               try {
-                                       // Enter/add own data
-                                       manager.doEnterOwnData();
-                               } catch (final ContactAlreadyAddedException ex) {
-                                       // Already added
-                                       this.outputMessage("Sie haben bereits Ihre eigenen Daten eingegeben.");
-                               }
-                               break;
-
-                       case '2': // Change own data
-                               manager.doChangeOwnData();
-                               break;
-
-                       case '3': // Add new addess
-                               manager.doAddOtherAddress();
-                               break;
-
-                       case '4': // List contacts
-                               manager.doListContacts();
-                               break;
-
-                       case '5': // Search addresses
-                               manager.doSearchContacts();
-                               break;
-
-                       case '6': // Change other addess
-                               manager.doChangeOtherAddress();
-                               break;
-
-                       case '7': // Delete other address
-                               manager.doDeleteOtherAddress();
-                               break;
+               // Try it!
+               try {
+                       // @TODO Rewrite this ugly switch() block
+                       switch (choice) {
+                               case '1':
+                                       try {
+                                               // Enter/add own data
+                                               manager.doEnterOwnData();
+                                       } catch (final ContactAlreadyAddedException ex) {
+                                               // Already added
+                                               this.outputMessage("Sie haben bereits Ihre eigenen Daten eingegeben.");
+                                       }
+                                       break;
+
+                               case '2': // Change own data
+                                       manager.doChangeOwnData();
+                                       break;
+
+                               case '3': // Add new addess
+                                       manager.doAddOtherAddress();
+                                       break;
+
+                               case '4': // List contacts
+                                       manager.doListContacts();
+                                       break;
+
+                               case '5': // Search addresses
+                                       manager.doSearchContacts();
+                                       break;
+
+                               case '6': // Change other addess
+                                       manager.doChangeOtherAddress();
+                                       break;
+
+                               case '7': // Delete other address
+                                       manager.doDeleteOtherAddress();
+                                       break;
 
                        case '0': {
                        try {
@@ -388,9 +391,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
                                break;
 
-                       default:
-                               // @TODO throw own exception
-                               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N
+                               default:
+                                       // @TODO throw own exception
+                                       throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N
+                       }
+               } catch (final IOException | BadTokenException ex) {
+                       // Something bad happened
+                       this.abortProgramWithException(ex);
                }
 
                // Trace message
index 8661516a33c291bb518c748640fc96a2fb212853..4bdb6e98baecf355f982dea847539d6225b190ef 100644 (file)
@@ -54,6 +54,7 @@ import org.mxchange.jcore.client.Client;
 import org.mxchange.jcore.client.gui.ClientFrame;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
 import org.mxchange.jcore.model.swing.contact.ContactTableModel;
 
@@ -209,7 +210,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
         * @param client Client instance
         */
        @Override
-       public void setupFrame (final Client client) {
+       public void setupFrame (final Client client) throws IOException, BadTokenException {
                // Debug line
                this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
 
@@ -682,6 +683,9 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                                        // Already added, log away
                                        // @TODO maybe output message here?
                                        self.logException(ex);
+                               } catch (final IOException | BadTokenException ex) {
+                                       // Somethind bad happened here
+                                       // @TODO Output error message here?
                                }
                        }
                });
@@ -702,7 +706,11 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                        @Override
                        public void actionPerformed (final ActionEvent e) {
                                ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
-                               manager.doChangeOwnData();
+                               try {
+                                       manager.doChangeOwnData();
+                               } catch (final IOException | BadTokenException ex) {
+                                       self.logException(ex);
+                               }
                        }
                });
 
index 2b93bf8d536e209a6877293a001ecd7343536722..912ad5b77201919182bb2f63a75c79937bae7eb6 100644 (file)
@@ -48,7 +48,7 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
         *
         * @param manager Manager instance
         * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported
-        * @throws java.sql.SQLException If any SQL error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
         */
        public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) throws UnsupportedDatabaseBackendException, SQLException {
                // Call own constructor
index 980c64b69490f047bb9727a651d8f1e6965ef889..ab71513ff8b1495d13fae858b0681d496e199d02 100644 (file)
@@ -64,7 +64,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * a client instance.
         *
         * @param client Client instance to use
-        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported
+        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured database backend is not supported
         * @throws java.sql.SQLException If an SQL error occurs
         */
        public AddressbookContactManager (final Client client) throws UnsupportedDatabaseBackendException, SQLException {
@@ -243,7 +243,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * Allows the user to change his/her own data
         */
        @Override
-       public void doChangeOwnData () {
+       public void doChangeOwnData () throws IOException , BadTokenException{
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -294,7 +294,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * Asks user for own data
         */
        @Override
-       public void doEnterOwnData () throws ContactAlreadyAddedException {
+       public void doEnterOwnData () throws ContactAlreadyAddedException, IOException , BadTokenException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -599,7 +599,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * @return Value from given row/column
         */
        @Override
-       public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) {
+       public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex));
 
@@ -644,7 +644,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * @return Whether own contact is already added
         */
        @Override
-       public boolean isOwnContactAdded () {
+       public boolean isOwnContactAdded () throws IOException, BadTokenException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -697,10 +697,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
 
                        // Add contact to internal list
                        this.addContact(contact);
-               } catch (final ContactAlreadyAddedException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               } catch (final BadTokenException ex) {
+               } catch (final ContactAlreadyAddedException | BadTokenException | IOException ex) {
                        // Abort here
                        this.abortProgramWithException(ex);
                }
index 651173090fd804d33dd5d49c3c574f156af8f0c2..77d39d35fca1cf335f2a07e7d1d53073eeb2f917 100644 (file)
  */
 package org.mxchange.addressbook.manager.contact;
 
+import java.io.IOException;
 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.manager.database.ManageableDatabase;
 
 /**
@@ -173,8 +175,10 @@ public interface ManageableAddressbookContact extends ManageableDatabase {
 
        /**
         * Let the user change own data
+        * @throws java.io.IOException If an IO error was found
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
         */
-       public void doChangeOwnData ();
+       public void doChangeOwnData () throws IOException , BadTokenException;
 
        /**
         * Let the user delete other address
@@ -184,8 +188,10 @@ public interface ManageableAddressbookContact extends ManageableDatabase {
        /**
         * Asks user for own data
         * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If own contact is already added
+        * @throws java.io.IOException If an IO error was found
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
         */
-       public void doEnterOwnData () throws ContactAlreadyAddedException;
+       public void doEnterOwnData () throws ContactAlreadyAddedException, IOException , BadTokenException;
 
        /**
         * Searches address book for a contact
@@ -197,6 +203,8 @@ public interface ManageableAddressbookContact extends ManageableDatabase {
         * isOwnContact flag
         *
         * @return Whether own contact is already added
+        * @throws java.io.IOException If an IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
         */
-       public boolean isOwnContactAdded ();
+       public boolean isOwnContactAdded () throws IOException, BadTokenException;
 }