Try

From Mesham
Jump to navigationJump to search

Syntax

try
{
try body
} catch (error string) {
error handing code
}

Semantics

Will execute the code in the try body and handle any errors. This is very important in parallel computing as it allows the programmer to easily deal with any communication errors that may occur. Exception handling is dynamic in Mesham and the last appropriate catch block will be entered into depending on program flow.

Error Strings

There are a number of error strings build into Mesham, additional ones can be specified by the programmer.

  • Array Bounds - Accessing an array outside its bounds
  • Divide by zero - Divide by zero error
  • Memory Out - Memory allocation failure
  • root Illegal - root process in communication
  • rank Illegal - rank in communication
  • buffer Illegal - buffer in communication
  • count - Count wrong in communication
  • type - Communication type error
  • comm - Communication communicator error
  • truncate - Truncation error in communication
  • Group - Illegal group in communication
  • op - Illegal operation for communication
  • arg - Arguments used for communication incorrect
  • oscli - Error returned by operating system when performing a system call

Example

#include <io>
#include <string>
function void main() {
   try {
      var t:array[Int,10];
      print(itostring(a[12]));
   } catch ("Array Bounds") {
      print("No Such Index\n");
   };
};

In this example the programmer is trying to access element 12 of array a. If this does not exist, then instead of that element being displayed an error message is put on the screen.

Since: Version 0.5