< Previous

Completed exceptionHandlingTest.egl file after lesson 7

This code is the completed version of the exceptionHandlingTest.egl file after lesson 7. If you see any errors marked by red X symbols in the file, make sure your code matches this code:
package programs;

import eglderbyr7.data.Customer;
import eglderbyr7.data.Orders;

program exceptionHandlingTest type BasicProgram {}
  
  function main()
    customer Customer;
    customer.FirstName = "John";
    customer.LastName = "Doe";
    customer.CustomerId = 1;
    
    customerOrder Orders;
    customerOrder.CustomerId = 1;
    customerOrder.OrderId = 50;
    customerOrder.OrderAmount = 0;
    customerOrder.OrderDetails = 
      "This is my first order, so get it right!";
  
    try
      add customerOrder;
      SysLib.writeStdout("Order added successfully.");
      add customer;
      SysLib.writeStdout("Customer added successfully.");
    onException(ex SQLException)
      SysLib.writeStdout("SQL exception "::ex.messageID);
      SysLib.writeStdout("message = "::ex.message);
      SysLib.writeStdout("Performing rollback.");
      SysLib.rollback();      
    end
    
    
    tempOrder Orders;
    tempOrder.OrderId = 50;
    get tempOrder;
    
    if (tempOrder is noRecordFound)
      SysLib.writeStdout("The order was rolled back successfully.");
    else
      SysLib.writeStdout("The order is still in the database");
    end
    
  end

end

Return to Lesson 7: Exception handling and rollbacks.

< Previous

Feedback