June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
8
Task/Exceptions/HolyC/exceptions-1.holyc
Normal file
8
Task/Exceptions/HolyC/exceptions-1.holyc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
try {
|
||||
U8 *err = 'Error';
|
||||
throw(err); // throw exception
|
||||
} catch {
|
||||
if (err == 'Error')
|
||||
Print("Raised 'Error'");
|
||||
PutExcept; // print the exception and stack trace
|
||||
}
|
||||
17
Task/Exceptions/HolyC/exceptions-2.holyc
Normal file
17
Task/Exceptions/HolyC/exceptions-2.holyc
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import Exceptions
|
||||
|
||||
procedure main(A)
|
||||
every i := !A do {
|
||||
case Try().call{ write(g(i)) } of {
|
||||
Try().catch(): {
|
||||
x := Try().getException()
|
||||
write(x.getMessage(), ":\n", x.getLocation())
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
procedure g(i)
|
||||
if numeric(i) = 3 then Exception().throw("bad value of "||i)
|
||||
return i
|
||||
end
|
||||
14
Task/Exceptions/Julia/exceptions.julia
Normal file
14
Task/Exceptions/Julia/exceptions.julia
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function extendedsqrt(x)
|
||||
try sqrt(x)
|
||||
catch
|
||||
if x isa Number
|
||||
sqrt(complex(x, 0))
|
||||
else
|
||||
throw(DomainError())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@show extendedsqrt(1) # 1
|
||||
@show extendedsqrt(-1) # 0.0 + 1.0im
|
||||
@show extendedsqrt('x') # ERROR: DomainError
|
||||
7
Task/Exceptions/VBA/exceptions-1.vba
Normal file
7
Task/Exceptions/VBA/exceptions-1.vba
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Sub foo1()
|
||||
err.raise(vbObjectError + 1050)
|
||||
End Sub
|
||||
|
||||
Sub foo2()
|
||||
Error vbObjectError + 1051
|
||||
End Sub
|
||||
46
Task/Exceptions/VBA/exceptions-2.vba
Normal file
46
Task/Exceptions/VBA/exceptions-2.vba
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
Sub bar1()
|
||||
'by convention, a simple handler
|
||||
On Error GoTo catch
|
||||
foo1
|
||||
MsgBox " No Error"
|
||||
Exit Sub
|
||||
catch:
|
||||
'handle all exceptions
|
||||
MsgBox Err.Number & vbCrLf & Err.Description
|
||||
Exit Sub
|
||||
End Sub
|
||||
|
||||
Sub bar2()
|
||||
'a more complex handler, illustrating some of the flexibility of VBA exception handling
|
||||
On Error GoTo catch
|
||||
100 foo1
|
||||
200 foo2
|
||||
'finally block may be placed anywhere: this is complexity for it's own sake:
|
||||
GoTo finally
|
||||
catch:
|
||||
If Erl = 100 Then
|
||||
' handle exception at first line: in this case, by ignoring it:
|
||||
Resume Next
|
||||
Else
|
||||
Select Case Err.Number
|
||||
Case vbObjectError + 1050
|
||||
' handle exceptions of type 1050
|
||||
MsgBox "type 1050"
|
||||
Case vbObjectError + 1051
|
||||
' handle exceptions of type 1051
|
||||
MsgBox "type 1051"
|
||||
Case Else
|
||||
' handle any type of exception not handled by above catches or line numbers
|
||||
MsgBox Err.Number & vbCrLf & Err.Description
|
||||
End Select
|
||||
Resume finally
|
||||
End If
|
||||
finally:
|
||||
'code here occurs whether or not there was an exception
|
||||
'block may be placed anywhere
|
||||
'by convention, often just a drop through to an Exit Sub, rather tnan a code block
|
||||
GoTo end_try:
|
||||
|
||||
end_try:
|
||||
'by convention, often just a drop through from the catch block
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue