class SimpleException{
public void a() throws Exception{
throw new Exception();
};
}
public class MyException {
public static void main(String[] args){
MyException e = new MyException();
SimpleException se = new SimpleException();
try {
se.a();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
class SimpleException{
public void a() throws Exception{
throw new Exception();
};
}
public class MyException {
public static void main(String[] args){
MyException e = new MyException();
try {
e.a();
} catch (SimpleException e1) {
e1.printStackTrace();
}
}
public void a() throws SimpleException{
throw new SimpleException();
}
}
class SimpleException extends Exception {};
SimpleException at MyException.a(MyException.java:15) at MyException.main(MyException.java:8) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Process finished with exit code 0
public void a() throws SimpleException,AException,BException{
throw new SimpleException();
}
public class MyException {
public static void main(String[] args){
MyException e = new MyException();
try {
e.a();
} catch (SimpleException e1) {
e1.printStackTrace();
} catch (BException e1) {
e1.printStackTrace();
} catch (AException e1) {
e1.printStackTrace();
}
}
public void a() throws SimpleException,AException,BException{
throw new SimpleException();
}
}
class SimpleException extends Exception {};
class AException extends Exception{}
class BException extends Exception{}
/**
* An element in a stack trace, as returned by {@link
* Throwable#getStackTrace()}. Each element represents a single stack frame.
* All stack frames except for the one at the top of the stack represent
* a method invocation. The frame at the top of the stack represents the
* execution point at which the stack trace was generated. Typically,
* this is the point at which the throwable corresponding to the stack trace
* was created.
*
* @since 1.4
* @author Josh Bloch
*/
public class MyException {
public static void main(String[] args){
MyException e = new MyException();
e.a();
public void a(){
try {
throw new Exception();
} catch (Exception e) {
StackTraceElement[] ste = e.getStackTrace();
System.out.println(ste.length);
}
}
}
public class MyException {
public static void main(String[] args){
MyException e = new MyException();
e.b();
}
public void b(){
try {
a();
} catch (Exception e) {
StackTraceElement[] ste = e.getStackTrace();
System.out.println(ste.length);
}
}
public void a() throws Exception{
throw new Exception();
}
}
public class MyException {
public static void main(String[] args){
MyException exception = new MyException();
try {
exception.c();
} catch (Exception e) {
StackTraceElement[] ste = e.getStackTrace();
System.out.println(ste.length);
System.out.println("---------------------------------------------------------------");
for (StackTraceElement s : e.getStackTrace()){
System.out.println(s.getClassName()+":method "+s.getMethodName()+" at line"+s.getLineNumber());
}
System.out.println("---------------------------------------------------------------");
}
}
public void c() throws Exception{
try {
a();
}catch (Exception e){
throw e;
}
}
public void a() throws Exception{
throw new Exception();
}
}
8 --------------------------------------------------------------- MyException:method a at line43 MyException:method c at line39 MyException:method main at line9 sun.reflect.NativeMethodAccessorImpl:method invoke0 at line-2 sun.reflect.NativeMethodAccessorImpl:method invoke at line57 sun.reflect.DelegatingMethodAccessorImpl:method invoke at line43 java.lang.reflect.Method:method invoke at line606 com.intellij.rt.execution.application.AppMain:method main at line144 --------------------------------------------------------------- Process finished with exit code 0
public class MyException {
public static void main(String[] args){
MyException exception = new MyException();
try {
exception.c();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void c() throws Exception{
try {
a();
}catch (Exception e){
throw e;
}
}
public void a() throws Exception{
throw new Exception("Exception from a()");
}
}
java.lang.Exception: Exception from a()
at MyException.a(MyException.java:40)
at MyException.c(MyException.java:30)
at MyException.main(MyException.java:21)
public class MyException {
public static void main(String[] args){
MyException exception = new MyException();
try {
exception.c();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void c() throws Exception{
try {
a();
}catch (Exception e){
// throw e;
throw (Exception)e.fillInStackTrace();
}
}
public void a() throws Exception{
throw new Exception("Exception from a()");
}
}
java.lang.Exception: Exception from a()
at MyException.c(MyException.java:22)
at MyException.main(MyException.java:10)
public class TestException {
public static void main(String[] args){
TestException testException = new TestException();
try {
testException.c();
} catch (CException e) {
e.printStackTrace();
}
}
public void a() throws AException{
AException aException = new AException("this is a exception");
throw aException;
}
public void b() throws BException{
try {
a();
} catch (AException e) {
throw new BException("this is b exception");
}
}
public void c() throws CException{
try {
b();
} catch (BException e) {
throw new CException("this is c exception");
}
}
}
class AException extends Exception{
public AException(String msg){
super(msg);
}
}
class BException extends Exception{
public BException(String msg){
super(msg);
}
}
class CException extends Exception{
public CException(String msg){
super(msg);
}
}
CException: this is c exception at TestException.c(TestException.java:31) at TestException.main(TestException.java:8)
public class TestException {
public static void main(String[] args){
TestException testException = new TestException();
try {
testException.c();
} catch (CException e) {
e.printStackTrace();
}
}
public void a() throws AException{
AException aException = new AException("this is a exception");
throw aException;
}
public void b() throws BException{
try {
a();
} catch (AException e) {
// throw new BException("this is b exception");
BException bException = new BException("this is b exception");
bException.initCause(e);
throw bException;
}
}
public void c() throws CException{
try {
b();
} catch (BException e) {
// throw new CException("this is c exception");
CException cException = new CException("this is c exception");
cException.initCause(e);
throw cException;
}
}
}
class AException extends Exception{
public AException(String msg){
super(msg);
}
}
class BException extends Exception{
public BException(String msg){
super(msg);
}
}
class CException extends Exception{
public CException(String msg){
super(msg);
}
}
CException: this is c exception at TestException.c(TestException.java:35) at TestException.main(TestException.java:8) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: BException: this is b exception at TestException.b(TestException.java:24) at TestException.c(TestException.java:32) ... 6 more Caused by: AException: this is a exception at TestException.a(TestException.java:15) at TestException.b(TestException.java:21) ... 7 more Process finished with exit code 0
try {
...
}catch (Exception e){
...
}finally {
//不管异常会不会被捕捉或者处理都会执行的代码,如关闭IO操作
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有