ErrorHandlingTest Class
From AgileApps Support Wiki
Revision as of 20:38, 14 November 2014 by imported>Aeric
This class explores a variety of error-handling conditions to determine what occurs, and when.
package com.platform.acme.test; import com.platform.api.*; public class ErrorHandlingTest { static int N = 0; /** * Invoke this method from a macro to run a selected test. */ public void runTests(Parameters p) throws Exception { test16(); } // Results of the tests: // 1. Nothing appears in the debug log unless you put it there. // (The unit test framework does. But errors by themselves do not.) // 2. Standard Java Exceptions do not produce a message. // (To generate one, catch standard Exceptions and call throwError().) // 2. Exception messages are invisible to the user unless generated using // "Functions.throwError(msg)" or "throw new Exception(msg)" // (Those two are equivalent to one another in every respect). // 3. With either of those, the last one is the ONLY message the user sees. // 4. If neither is called, then ALL showMessage() items are seen, in a // concatenated string. // 5. A message is usually displayed in a popup. // (In some cases, it appears at the top of the page.) // 6. If an exception with no message, no popup appears: "throw new Exception()" public void test16() throws Exception { N = 16; Functions.throwError(""); // THE USER SEES AN EMPTY DIALOG WITH THE TITLE, "Error". } public void test15() throws Exception { N = 15; try { throwStandardJavaException(); } catch (Exception e) { throw e; } // THE USER SEES NOTHING. } public void test14() throws Exception { N = 14; try { throwAnError(); } catch (Exception e) { throw e; } // THE USER SEES THE throwError() MESSAGE. } public void test13() throws Exception { N = 13; try { throwCustomException(); } catch (Exception e) { Functions.throwError("Test"+N+": Replacement message"); } // THE USER SEES THE REPLACEMENT MESSAGE. } public void test12() throws Exception { N = 12; try { throwCustomException(); } catch (Exception e) { throw e; } // THE USER SEES THE ORIGINAL EXCEPTION MESSAGE. } public void test11() throws Exception { N = 11; try { throwCustomException(); } catch (Exception e) { // do nothing } // THE USER SEES NOTHING. } public void test10() throws Exception { N = 10; Functions.showMessage("Test "+N+" -- msg part 1<br>"); throw new Exception("Test "+N+" -- throwError"); // THE USER SEES A POPUP WITH THE EXCEPTION. showMessage text is NOT seen. } public void test9() throws Exception { N = 9; Functions.showMessage("Test "+N+" -- msg part 1<br>"); Functions.throwError("Test "+N+" -- throwError"); // THE USER SEES A POPUP WITH THE ERROR. showMessage text is NOT seen. } public void test8() throws Exception { N = 8; Functions.showMessage("Test "+N+" -- part 1<br>"); showAMessage(); // THE USER SEES A POPUP WITH BOTH MESSAGES CONCATENATED. } public void test7() throws Exception { N = 7; Functions.showMessage("Test "+N+" -- part 1<br>"); Functions.showMessage("Test "+N+" -- part 2"); // THE USER SEES A POPUP WITH BOTH MESSAGES CONCATENATED. } public void test6() throws Exception { N = 6; throwAnError(); // THE USER SEES POPUP WITH THE MESSAGE. THE DEBUG LOG SHOWS NOTHING. } public void test5() throws Exception { N = 5; Functions.throwError("Test "+ N); // THE USER SEES POPUP WITH THE MESSAGE. THE DEBUG LOG SHOWS NOTHING. } public void test4() throws Exception { N = 4; throwStandardJavaException(); // THE USER SEES NOTHING THE DEBUG LOG SHOWS NOTHING. } public void test3() throws Exception { N = 3; throw new ArrayIndexOutOfBoundsException(); // THE USER SEES NOTHING THE DEBUG LOG SHOWS NOTHING. } public void test2() throws Exception { N = 2; throwCustomException(); // THE USER SEES POPUP WITH CUSTOM MESSAGE. THE DEBUG LOG SHOWS NOTHING. // (If there is no message, the popup is not displayed.) } public void test1() throws Exception { N = 1; throw new Exception("Test Exception"); // THE USER SEES POPUP WITH CUSTOM MESSAGE. THE DEBUG LOG SHOWS NOTHING. // (If there is no message, the popup is not displayed.) } //************************************************************************* // UTILITY METHODS public void throwCustomException() throws Exception { // Throw an exception with an customized message throw new Exception("Test "+N+": Exception"); } public void throwStandardJavaException() throws Exception { // Throw a standard Java exception throw new ArrayIndexOutOfBoundsException(); } public void throwStandardExceptionWithMessage() throws Exception { // Throw a standard Java exception that includes a message throw new ArrayIndexOutOfBoundsException("IO Exception"); } public void throwAnError() throws Exception { // Call the error method Functions.throwError("Test "+N+": throwError"); } public void showAMessage() throws Exception{ // Call the error method Functions.showMessage("Test "+N+" -- part 2"); } }