-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.cs
164 lines (144 loc) · 5.05 KB
/
Exceptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Copyright (C) 2008 Eugeny Grishul
//
// See license in License.txt
//
using System;
namespace NObjective
{
/// <summary>
/// The exception that is thrown when Objective-C exception was trapped.
/// </summary>
public sealed class RuntimeException : Exception
{
/// <summary>
/// Original Objective-C exception that produced that.
/// </summary>
public RuntimeObject Object { get; private set; }
/// <summary>
/// Description from original Objective-C exception that describes the error.
/// </summary>
public override string Message { get { return Object.InvokeString( Selectors.description ); } }
/// <summary>
/// Initializes new instance of RuntimeException.
/// </summary>
public RuntimeException()
{ }
/// <summary>
/// Releases internal native exception.
/// </summary>
~RuntimeException()
{
Runtime.ReleaseNativeObject( Object );
}
/// <summary>
/// Initializes new instance of RuntimeException class with specified Objective-C exception.
/// </summary>
/// <param name="object">Original Objective-C exception.</param>
public RuntimeException( RuntimeObject @object )
{
Object = @object;
Runtime.RetainNativeObject( Object );
}
/// <summary>
/// Extracts information about managed exception passed throught native barrier via ExceptionProxy
/// or creates new instance of RuntimeException class with specified Objective-C exception.
/// </summary>
/// <param name="object">Original Objective-C exception.</param>
/// <returns>New exception instance.</returns>
public unsafe static Exception Create( RuntimeObject @object )
{
if( @object.Class == Runtime.ExceptionProxy.Class )
{
var result = ( ( Runtime.ExceptionProxy* ) ( IntPtr ) @object )->ManagedException;
Runtime.ReleaseNativeObject( @object );
return result;
}
return new RuntimeException( @object );
}
}
/// <summary>
/// The exception that is thrown when errors are occured while class registration.
/// </summary>
public sealed class RegistrationException : Exception
{
/// <summary>
/// Initializes new instance of RegistrationException class.
/// </summary>
public RegistrationException()
{ }
/// <summary>
/// Initializes new instance of RegistrationException class with specified message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public RegistrationException( string message )
: base( message )
{
}
/// <summary>
/// Initializes new instance of RegistrationException class with specified formatting string and appropriate arguments.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arguments">An System.Object array containing zero or more objects to format.</param>
public RegistrationException( string format, params object[] arguments )
: base( string.Format( format, arguments ) )
{
}
}
/// <summary>
/// The exception that is thrown when errors are occered while Objective-C interop.
/// </summary>
public sealed class InteropException : Exception
{
/// <summary>
/// Initializes new instance of InteropException class.
/// </summary>
public InteropException()
{ }
/// <summary>
/// Initializes new instance of InteropException class with specified message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public InteropException( string message )
: base( message )
{
}
/// <summary>
/// Initializes new instance of InteropException class with specified formatting string and appropriate arguments.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arguments">An System.Object array containing zero or more objects to format.</param>
public InteropException( string format, params object[] arguments )
: base( string.Format( format, arguments ) )
{
}
}
/// <summary>
/// The exception that is thrown when accessing to ivars from released exported class instance.
/// </summary>
public sealed class ObjectReleasedException : Exception
{
/// <summary>
/// Initializes new instance of ObjectReleasedException class.
/// </summary>
public ObjectReleasedException()
{ }
/// <summary>
/// Initializes new instance of ObjectReleasedException class with specified message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ObjectReleasedException( string message )
: base( message )
{
}
/// <summary>
/// Initializes new instance of ObjectReleasedException class with specified formatting string and appropriate arguments.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arguments">An System.Object array containing zero or more objects to format.</param>
public ObjectReleasedException( string format, params object[] arguments )
: base( string.Format( format, arguments ) )
{
}
}
}