I decided to go ahead an try this out myself.  What I came up with seems to
work.  What are the pitfalls of this approach?


New Module:
ErrorTrapper

New Method in ErrorTrapper:
Error, with Parameters, Err as RunTimeException, Message as String,
Explanation as String, Icon as Integer, ActionText as String, AlternateOn as
Boolean, AlternateText as String, CancelOn as Boolean)

Error:
  
  Dim d as New MessageDialog
  Dim b as MessageDialogButton
  Dim errString as String
  
  If Err IsA IllegalCastException then
    errString = "Illegal Cast Exception"
  ElseIf Err IsA KeyNotFoundException then
    errString = "Key Not Found Exception"
  ElseIf Err IsA NilObjectException then
    errString = "Nil Object Exception"
  ElseIf Err IsA OutOfBoundsException then
    errString = "Out of Bounds Exception"
  ElseIf Err IsA OutOfMemoryException then
    errString ="Out Of Memory Exception"
  ElseIf Err IsA RbScriptAlreadyRunningException then
    errString = "RB Script Already Running Exception"
  ElseIf Err IsA RbScriptException then
    errString = "RB Script Exception"
  ElseIf Err IsA RegExException then
    errString = "RegEx Exception"
  ElseIf Err IsA ShellNotAvailableException then
    errString = "Shell Not Available Exception"
  ElseIf Err IsA ShellNotRunningException then
    errString = "Shell Not Running Exception"
  ElseIf Err IsA stackOverflowException then
    errString = "Stack Overflow Exception"
  ElseIf Err IsA typeMismatchException then
    errString = "Type Mismatch Exception"
  ElseIf Err IsA UnsupportedFormatException then
    errString = "Unsupported Format Exception"
  ElseIf Err IsA TypeMismatchException then
    errString = "Type Mismatch Exception"
  Else
    errString = "Unknown Error."
  End if
  
  If Message = "" then
    Message = "An error occurred."
  End If
  
  If Explanation = "" then
    Explanation = errString
  End If
  
  d.Icon = Icon
  d.ActionButton.Caption = ActionText
  d.CancelButton.Visible = CancelOn
  d.AlternateActionButton.Visible = AlternateOn
  d.AlternateActionButton.Caption = AlternateText
  d.Message = Message
  d.Explanation = Explanation
  d.Title = errString
  
  b = d.ShowModal
  Select Case b
    
  Case d.ActionButton
    // User pressed Action button
  Case d.AlternateActionButton 
    // User pressed Alternate Action Button
  Case d.CancelButton 
    // User pressed Cancel
  End select
  
  In App.UnhandledException:
  Error(error, "Unhandled Exception","An error occurred and it was not
properly handled.", 2, "OK", False, "", False)
  Return True

Main code example:
  // NilObjectException
  If file = nil or file.Exists = False then
    Error(err, "Error reading file","File cannot be found.", 2, "OK", True,
"", False)
  Else
    Continue
  End If

  // OutOfBoundsException
  Dim i, nFonts as Integer
  nFonts=FontCount
  For i=1 to nFonts //dont do this!
    ListBox1.addrow(Font(i))
  Next
  
Exception err 
  Error(err, "","", 2, "Skip", True, "Try Again", True)

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to