public RaiseException newPgError(ThreadContext context, String message, ResultSet result, org.jcodings.Encoding encoding) {
RubyClass klass = context.runtime.getModule("PG").getClass("Error");
RubyString rubyMessage = context.runtime.newString(message);
if (encoding != null) {
RubyEncoding rubyEncoding = RubyEncoding.newEncoding(context.runtime, encoding);
rubyMessage = (RubyString) rubyMessage.encode(context, rubyEncoding);
}
IRubyObject rubyResult = result == null ? context.nil : createResult(context, result, NULL_ARRAY, Block.NULL_BLOCK);
IRubyObject exception = klass.newInstance(context, rubyMessage, rubyResult, Block.NULL_BLOCK);
return new RaiseException((RubyException) exception);
}