示例#1
0
文件: file.cpp 项目: richcole/RJL
Object* native_file_close(Object *cxt, Object *frame, Object *self) {
  FileBuffer *file_buf = get_file_buffer(self);
  if ( file_buf == 0 ) {
    return new_exception(cxt, frame, "Expected a file as first argument");
  }
  if ( file_buf->file == 0 ) {
    return new_exception(cxt, frame, "File pointer is null");
  }
  int result = fclose(file_buf->file);
  if ( result != 0 ) {
    return new_errno_exception(cxt, frame, "Failed while closing file");
  }
  return frame;
}
示例#2
0
// Throw an exception with a message and a cause
void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, symbolHandle h_name, const char* message, Handle h_cause, Handle h_loader, Handle h_protection_domain) {
  // Check for special boot-strapping/vm-thread handling
  if (special_exception(thread, file, line, h_name, message)) return;
  // Create and throw exception and init cause
  Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain);
  _throw(thread, file, line, h_exception, message);
}
示例#3
0
// Creates an exception oop, calls the <init> method with the given signature.
// and returns a Handle
// Initializes the cause if cause non-null
Handle Exceptions::new_exception(Thread *thread, Symbol* name,
                                 Symbol* signature, JavaCallArguments *args,
                                 Handle h_cause,
                                 Handle h_loader, Handle h_protection_domain) {
    Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);

    // Future: object initializer should take a cause argument
    if (h_cause.not_null()) {
        assert(h_cause->is_a(SystemDictionary::Throwable_klass()),
               "exception cause is not a subclass of java/lang/Throwable");
        JavaValue result1(T_OBJECT);
        JavaCallArguments args1;
        args1.set_receiver(h_exception);
        args1.push_oop(h_cause);
        JavaCalls::call_virtual(&result1, h_exception->klass(),
                                vmSymbols::initCause_name(),
                                vmSymbols::throwable_throwable_signature(),
                                &args1,
                                thread);
    }

    // Check if another exception was thrown in the process, if so rethrow that one
    if (thread->has_pending_exception()) {
        h_exception = Handle(thread, thread->pending_exception());
        thread->clear_pending_exception();
    }
    return h_exception;
}
示例#4
0
void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol* name, Handle h_cause,
                              Handle h_loader, Handle h_protection_domain) {
    // Check for special boot-strapping/vm-thread handling
    if (special_exception(thread, file, line, h_cause)) return;
    // Create and throw exception
    Handle h_exception = new_exception(thread, name, h_cause, h_loader, h_protection_domain);
    _throw(thread, file, line, h_exception, NULL);
}
示例#5
0
void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* name, Symbol* signature, JavaCallArguments *args) {
    // Check for special boot-strapping/vm-thread handling
    if (special_exception(thread, file, line, name, NULL)) return;
    // Create and throw exception
    Handle h_loader(thread, NULL);
    Handle h_prot(thread, NULL);
    Handle exception = new_exception(thread, name, signature, args, h_loader, h_prot);
    _throw(thread, file, line, exception);
}
示例#6
0
文件: file.cpp 项目: richcole/RJL
Object* native_file_open_mode(Object *cxt, Object *frame, Object *self) {
  Object *stack = get(cxt, frame, "stack");
  CharArrayBuffer *file_mode_buf = get_char_array_buffer(pop(cxt, stack));
  CharArrayBuffer *file_name_buf = get_char_array_buffer(pop(cxt, stack));
  if ( file_name_buf == 0 ) {
    return new_exception(cxt, frame, "Expected a char_array as first argument");
  }
  if ( file_mode_buf == 0 ) {
    return new_exception(cxt, frame, "Expected a char_array as second argument");
  }
  FILE *fp = fopen(file_name_buf->data, file_mode_buf->data);
  if ( fp == 0 ) {
    return new_exception(cxt, frame, "Unable to open file");
  }
  else {
    Object *file_object = new_file(cxt, fp);
    set(cxt, file_object, "parent", self);
    push(cxt, stack, file_object);
    return frame;
  }
}
示例#7
0
文件: file.cpp 项目: richcole/RJL
Object* native_file_read_into_offset_length(Object *cxt, Object *frame, Object *self) {
  Object *stack = get_stack(cxt, frame);
  
  FileBuffer *file_buf = get_file_buffer(self);
  Object *length_obj   = pop(cxt, stack);
  Object *offset_obj   = pop(cxt, stack);
  Object *char_array   = pop(cxt, stack);

  if ( file_buf == 0 ) {
  	return new_exception(cxt, frame, "Expected a file as self argument");
  }

  CharArrayBuffer *char_array_buf = get_char_array_buffer(char_array);
  if ( char_array_buf == 0 ) {
  	return new_exception(cxt, frame, "Expected a char_array as first argument");
  }

  if ( ! is_boxed_int(cxt, offset_obj) ) {
  	return new_exception(cxt, frame, "Expected a boxed int as second argument");
  }
  Fixnum offset = boxed_int_to_fixnum(cxt, offset_obj);
  
  if ( ! is_boxed_int(cxt, length_obj) ) {
  	return new_exception(cxt, frame, "Expected a fixnum as third argument");
  }
  Fixnum length = boxed_int_to_fixnum(cxt, length_obj);

  if ( offset + length > char_array_buf->reserved ) {
  	return new_exception(cxt, frame, "Offset + length exceeds char_array length");
  }
  
  int num_read = fread(char_array_buf->data + offset, 1, length, file_buf->file);
  if ( num_read >= 0 ) {
    char_array_truncate_buffer(cxt, char_array, offset + num_read);
    return frame;
  }
  else {
  	return new_errno_exception(cxt, frame, "Unable to read from file");
  }
}
示例#8
0
文件: file.cpp 项目: richcole/RJL
Object* native_file_eof(Object *cxt, Object *frame, Object *self) {
  Object *stack = get(cxt, frame, "stack");
  FileBuffer *file_buf = get_file_buffer(self);
  if ( file_buf == 0 ) {
  	return new_exception(cxt, frame, "Expected a file as first argument");
  }
  if ( feof(file_buf->file) ) {
    push(cxt, stack, get_true(cxt));
  }
  else {
    push(cxt, stack, get_false(cxt));
  }
  return frame;
};
示例#9
0
// Convenience method. Calls either the <init>() or <init>(Throwable) method when
// creating a new exception
Handle Exceptions::new_exception(Thread* thread, Symbol* name,
                                 Handle h_cause,
                                 Handle h_loader, Handle h_protection_domain,
                                 ExceptionMsgToUtf8Mode to_utf8_safe) {
    JavaCallArguments args;
    Symbol* signature = NULL;
    if (h_cause.is_null()) {
        signature = vmSymbols::void_method_signature();
    } else {
        signature = vmSymbols::throwable_void_signature();
        args.push_oop(h_cause);
    }
    return new_exception(thread, name, signature, &args, h_loader, h_protection_domain);
}
示例#10
0
void NLog::append_to_log(LogMessage::Type type, bool fromServer,
                       const QString & message)
{
  QString header = "[ %1 ][ %2 ] ";
  QString msg;

  header = header.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  header = header.arg(fromServer ? "Server" : "Client");

  msg = message;
  msg.replace('\n', QString("\n%1").arg(header));
  msg.prepend(header);

  emit new_message(msg, type);

  if(type == LogMessage::EXCEPTION)
    emit new_exception(message);
}
示例#11
0
// Convenience method. Calls either the <init>() or <init>(String) method when
// creating a new exception
Handle Exceptions::new_exception(Thread* thread, symbolHandle h_name,
                                 const char* message, Handle h_cause,
                                 Handle h_loader,
                                 Handle h_protection_domain,
                                 ExceptionMsgToUtf8Mode to_utf8_safe) {
  JavaCallArguments args;
  symbolHandle signature;
  if (message == NULL) {
    signature = vmSymbolHandles::void_method_signature();
  } else {
    // We want to allocate storage, but we can't do that if there's
    // a pending exception, so we preserve any pending exception
    // around the allocation.
    // If we get an exception from the allocation, prefer that to
    // the exception we are trying to build, or the pending exception.
    // This is sort of like what PRESERVE_EXCEPTION_MARK does, except
    // for the preferencing and the early returns.
    Handle incoming_exception (thread, NULL);
    if (thread->has_pending_exception()) {
      incoming_exception = Handle(thread, thread->pending_exception());
      thread->clear_pending_exception();
    }
    Handle msg;
    if (to_utf8_safe == safe_to_utf8) {
      // Make a java UTF8 string.
      msg = java_lang_String::create_from_str(message, thread);
    } else {
      // Make a java string keeping the encoding scheme of the original string.
      msg = java_lang_String::create_from_platform_dependent_str(message, thread);
    }
    if (thread->has_pending_exception()) {
      Handle exception(thread, thread->pending_exception());
      thread->clear_pending_exception();
      return exception;
    }
    if (incoming_exception.not_null()) {
      return incoming_exception;
    }
    args.push_oop(msg);
    signature = vmSymbolHandles::string_void_signature();
  }
  return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain);
}
job_receiver::job_receiver(std::string the_jobfilenamepattern) {
  try {
    XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Initialize();
  }
  catch (const XERCES_CPP_NAMESPACE_QUALIFIER XMLException& toCatch) {
    char* ini_error=XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toCatch.getMessage());
    job_exception new_exception(std::string("xerces initialisation error: ")+ini_error);
    XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&ini_error);
    throw new_exception;
  }

  jobfilename=NULL;
  setFilenamePattern(the_jobfilenamepattern);
  parser=new XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser();
  if (parser==NULL) {
    delete jobfilename;
    throw job_exception("could not allocate parser");
  }
  parser->setValidationScheme(XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser::Val_Always);
  parser->setDoNamespaces(true);
  errHandler = (XERCES_CPP_NAMESPACE_QUALIFIER ErrorHandler*) new XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase();
  parser->setErrorHandler(errHandler);
}
示例#13
0
Object *new_exception(Object *cxt, Object *frame, char const* reason) {
  return new_exception(cxt, frame, new_char_array(cxt, reason));
}
示例#14
0
		void register_type(int code, const char *name) {
			register_type(code, new_exception(name, m_type.ptr()));
		}
示例#15
0
		void initialize() {
			m_type = new_exception("Error");
			register_type(-ENOENT, "NotFoundError");
			register_type(-ETIMEDOUT, "TimeoutError");
		}
示例#16
0
文件: file.cpp 项目: richcole/RJL
Object *new_errno_exception(Object *cxt, Object *frame, char const* message) {
  Object *ex = new_exception(cxt, frame, message);
  set(cxt, ex, "error", new_char_array(cxt, strerror(errno)));
  return ex;
};