inherit custom errors from StandardError

This commit is contained in:
Richard Ramsden 2012-03-11 22:33:22 -07:00
parent 910924a36d
commit 5663788eb8
2 changed files with 11 additions and 19 deletions

View file

@ -1,3 +1,7 @@
module X11
class X11Error < StandardError; end
end
require 'socket' require 'socket'
require 'active_support' require 'active_support'
require 'hexdump' require 'hexdump'
@ -6,8 +10,3 @@ require 'X11/auth'
require 'X11/display' require 'X11/display'
require 'X11/encode' require 'X11/encode'
require 'X11/packet' require 'X11/packet'
module X11
class X11Error < StandardError; end
class X11Exception < RuntimeException; end
end

View file

@ -1,15 +1,8 @@
module X11 module X11
class DisplayException < X11Exception; end class DisplayError < X11Error; end
class ConnectionException < DisplayException; end class ConnectionError < DisplayError; end
class AuthorizationError < ConnectionError; end
class AuthorizationException < ConnectionException
attr_reader :errorcode
def initialize msg, errcode=nil
super msg
@errorcode = errcode
end
end
class Display class Display
@ -53,14 +46,14 @@ private
when X11::Auth::FAILED when X11::Auth::FAILED
len, major, minor, xlen = @socket.read(7).unpack("CSSS") len, major, minor, xlen = @socket.read(7).unpack("CSSS")
reason = @socket.read(xlen * 4) reason = @socket.read(xlen * 4)
reason = reason[0..len] reason = reason[0..len]
raise AuthorizationException.new "Connection to server failed -- (version #{major}.#{minor}) #{reason}", X11::Auth::FAILED raise AuthorizationError, "Connection to server failed -- (version #{major}.#{minor}) #{reason}"
when X11::Auth::AUTHENTICATE when X11::Auth::AUTHENTICATE
raise AuthorizationException.new "Connection requires authentication", X11::Auth::AUTHENTICATE raise AuthorizationError, "Connection requires authentication"
when X11::Auth::SUCCESS when X11::Auth::SUCCESS
puts "CONNECTION SUCCESS" puts "CONNECTION SUCCESS"
else else
raise AuthorizationException.new "Received unknown opcode #{type}" raise AuthorizationError, "Received unknown opcode #{type}"
end end
end end