Class

KeychainException


Description

A method of the Keychain or KeychainItem classes failed. See the error code returned by KeychainException to diagnose the problem.

Properties

Name

Type

Read-Only

Shared

ErrorNumber

Integer

Message

String

Methods

Name

Parameters

Returns

Shared

Constructor

message As String = "", errorCode As Integer = 0

Stack

String()

StackFrames

StackFrame()

Property descriptions


KeychainException.ErrorNumber

ErrorNumber As Integer

Used to contain an error number that describes the runtime error.

The following example displays a message box if, for example, you try to create more than one KeychainItem for the same application.

Var newItem As KeychainItem
If System.KeychainCount > 0 Then
  newItem = New KeychainItem
  ' Indicate the name of the application
  newItem.ServiceName = "MyApplication"

  ' Create a new keychain item for the application and assign the password
  System.Keychain.AddPassword(newItem, "SecretPassword")
Else
  System.Beep
  MessageBox("You don't have a key chain.")
End If
Exception err As KeychainException
  MessageBox(err.Message + ". Error Code: " + err.ErrorNumber.ToString)

KeychainException.Message

Message As String

Used to contain descriptive text to display when the runtime exception is encountered.

The following example displays a message box if, for example, you try to create more than one KeychainItem for the same application.

Var newItem As KeyChainItem
If System.KeyChainCount > 0 Then
  newItem = New KeyChainItem
  ' Indicate the name of the application
  newItem.ServiceName = "MyApplication"

  ' Create a new keychain item for the application and assign the password
  System.KeyChain.AddPassword(newItem, "SecretPassword")
Else
  System.Beep
  MessageBox("You don't have a key chain.")
End If
Exception err As KeyChainException
  MessageBox(err.Message + ". Error Code: " + err.ErrorNumber.ToString)

Method descriptions


KeychainException.Constructor

Constructor(message As String = "", errorCode As Integer = 0)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Used to raise your own RuntimeException with a message and optional error code.


KeychainException.Stack

Stack As String()

Returns a String array that contains a list of all of the methods in the stack from the main entrypoint to the point at which the exception was invoked.

The stack contains all the method names up and including the current method name.

This feature only works if the IncludeFunctionNames property on the App object is selected in the Shared Build Settings.

In addition to your own method calls, you will also see framework method calls, but these may not always be completely accurate due to insufficient symbols for the OS to resolve.


KeychainException.StackFrames

StackFrames As StackFrame()

Returns an array containing the stack when the exception was first raised.

Notes

The following tables shows the values of ErrorNumber and the associated text returned in the Message property.

Error Number

Message

-128

User Cancelled.

-25291

Keychain not available.

-25292

Keychain read only.

-25293

Keychain Authorization failed.

-25294

No such Keychain.

-25295

Invalid Keychain.

-25296

Duplicate Keychain.

-25797

Keychain Duplicate Callback.

-25298

Keychain Invalid Callback.

-25299

Keychain Duplicate Item.

-25300

Keychain Item Not Found.

-25301

Keychain Buffer Too Small.

-25302

Keychain Data Too Large.

-25303

Keychain No Such Attribute.

-25304

Keychain Invalid Item Reference.

-25305

Keychain Invalid Search Reference.

-25306

Keychain No Such Class.

-25307

No Default Keychain.

-25308

Keychain Interaction Not Allowed.

-25309

Keychain Read Only Attribute.

-25310

Wrong Keychain Version.

-25311

Keychain Key Size Not Allowed.

-25312

Keychain No Storage Module.

-25313

Keychain No Certificate Module.

-25314

Keychain No Policy Module.

-25315

Keychain Interaction Required.

-25316

Keychain Data Not Available.

-25317

Keychain Data Not Modifiable.

-25318

Keychain Create Chain Failed.

Sample code

The following example displays a message box if, for example, you try to create more than one KeychainItem for the same application.

Var NewItem As KeychainItem
If System.KeychainCount > 0 Then
  newItem = New KeychainItem
  ' Indicate the name of the application
  newItem.ServiceName = "MyApplication"

  Try
    ' Create a new keychain item for the application and assign the password
    System.Keychain.AddPassword(newItem, "SecretPassword")
  Catch error As KeychainException
    MessageBox(error.Message + ". Error Code: " + error.errorNumber.ToString)
  End Try
Else
  System.Beep
  MessageBox("You don't have a key chain.")
End If

The following example uses an Exception block to display a message box if the application specified by ServiceName does not have a KeychainItem.

Var itemToFind As KeychainItem
Var password As String

itemToFind = New KeychainItem

' Indicate the name of the application whose keychain item you wish to find
itemToFind.ServiceName = "MyApplication"

Try
  ' get application's password from the system keychain
  password = System.Keychain.FindPassword(itemToFind)
  MessageBox("The password for this item is: " + password)
Catch error As KeychainException
  MessageBox("Can't find item: " + error.Message)
End Try

Compatibility

All project types on all supported operating systems.

See also

RuntimeException parent class; Keychain, KeychainItem, RuntimeException classes; System module.