vb2Py

  VB Error Handling
Python equivalents of VB's Error handling

QuickLinks

VB keywords

VB control structures

Subroutines and Functions

Classes

 


 
  Home
  News
  Downloads
  Documentation
  Screenshots
  Online Version
  Links
  Contribute

Simple Example - Trapping

VB Code

On Error Goto HANDLER
    Statements1
HANDLER:
    Statements2

Python Code
try:
    Statements1
except:
    Statements2

Ugly Example - Ignoring Errors

VB Code

On Error Resume Next
    Statement1
    Statement2
    StatementN
On Error Goto 0
    Statements

Python Code
try: Statement1
except: pass
try: Statement2
except: pass
try: StatementN
except: pass
Statements

 

Tough Example - Resuming Errors

VB Code

On Error Goto HANDLER
    Statement1
IGNORE:
    Statement2
    StatementN
HANDLER:
    If Cond1 Then
        Resume
    Else If Cond2 Then
        Retry
    Else
        Resume IGNORE
    End If

Python Code


while 1:
    try:
        Statement1
    except:
        if Cond2: continue
        break

while 1:
    try:
        Statement2
        StatementN
    except:
        if
Cond1: break

 

 

    SourceForge.net Logo