You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/07 16:50:24 UTC

svn commit: r762800 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/exception/OperatingSystemException.java native/shared/error.c

Author: mturk
Date: Tue Apr  7 14:50:24 2009
New Revision: 762800

URL: http://svn.apache.org/viewvc?rev=762800&view=rev
Log:
OS exception helper code

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c   (with props)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java?rev=762800&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java Tue Apr  7 14:50:24 2009
@@ -0,0 +1,36 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.exception;
+
+/** OperatingSystemException
+ *
+ * @author Mladen Turk
+ *
+ */
+
+public class OperatingSystemException extends Exception {
+
+    public OperatingSystemException()
+    {
+        super();
+    }
+
+    public OperatingSystemException(String msg)
+    {
+        super(msg);
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/OperatingSystemException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=762800&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Tue Apr  7 14:50:24 2009
@@ -0,0 +1,115 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+
+/*
+ * Convenience function to help throw any class
+ */
+ACR_DECLARE(void) ACR_ThrowClass(JNIEnv *env, const char *clazz,
+                                 const char *msg)
+{
+    jclass ec;
+
+    ec = (*env)->FindClass(env, clazz);
+    if (ec == NULL) {
+        fprintf(stderr, "Cannot find %s class\n", clazz);
+        return;
+    }
+    (*env)->ThrowNew(env, ec, msg);
+    (*env)->DeleteLocalRef(env, ec);
+}
+
+/*
+ * Convenience function to help throw any class with
+ * file and line number from where the exception was called.
+ */
+ ACR_DECLARE(void) ACR_ThrowClassEx(JNIEnv *env, const char *clazz,
+                                    const char *file, int line,
+                                    const char *msg)
+{
+    if (file) {
+        char fmt[ACR_HBUFFER_SIZ];
+        char *f = (char *)(file + strlen(file) - 1);
+        while (f != file && '\\' != *f && '/' != *f) {
+            f--;
+        }
+        if (f != file) {
+            f++;
+        }
+        if (msg)
+            sprintf(fmt, "%s (%s)+%d", msg, f, line);
+        else
+            sprintf(fmt, "(%s)+%d", msg, f, line);
+        ACR_ThrowClass(env, clazz, &fmt[0]);
+    }
+    else {
+        ACR_ThrowClass(env, clazz, msg);
+    }
+}
+
+
+/*
+ * Convenience function to help throw an java.lang.Exception.
+ */
+ACR_DECLARE(void) ACR_ThrowException(JNIEnv *env, const char *msg)
+{
+    ACR_ThrowClass(env, "java/lang/Exception", msg);
+}
+
+/*
+ * Convenience function to help throw an java.io.IOException.
+ */
+ACR_DECLARE(void) ACR_ThrowIOException(JNIEnv *env, const char *msg)
+{
+    ACR_ThrowClass(env, "java/io/IOException", msg);
+}
+
+/*
+ * Convenience function to help throw an java.lang.OutOfMemoryError.
+ */
+ACR_DECLARE(void) ACR_ThrowMemoryException(JNIEnv *env, const char *file,
+                                           int line, const char *msg)
+{
+    ACR_ThrowClassEx(env, "java/lang/OutOfMemoryError", file, line, msg);
+}
+
+/*
+ * Convenience function to help throw an java.lang.NullPointerException.
+ */
+ACR_DECLARE(void) ACR_ThrowNullPointerException(JNIEnv *env, const char *file,
+                                                int line, const char *msg)
+{
+    ACR_ThrowClassEx(env, "java/lang/NullPointerException", file, line, msg);
+}
+
+/*
+ * Convenience function to help throw an java.lang.IllegalArgumentException.
+ */
+ACR_DECLARE(void) ACR_ThrowArgumentException(JNIEnv *env, const char *file,
+                                             int line, const char *msg)
+{
+    ACR_ThrowClassEx(env, "java/lang/IllegalArgumentException", file, line, msg);
+}
+
+
+ACR_DECLARE(void) ACR_ThrowOSException(JNIEnv *env, const char *msg)
+{
+    ACR_ThrowClassEx(env, ACR_CLASS_PATH "exception/OperatingSystemException",
+                     msg);
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
------------------------------------------------------------------------------
    svn:eol-style = native