我正在使用第三方庫,它以String(非Exception對象)的形式返回異常信息。我想提取字符串堆棧跟蹤的某些部分以在GUI中顯示用戶。從Java中提取文本字符串
兩個例子:
com.sdf.configure.model.change.InvalidChangeException: transformed change validation failed
at com.sdf.configure.model.change.SimpleConfigChanger.performChange(SimpleConfigChanger.java:129)
at com.sdf.portal.service.QosPolicyServiceImpl.applyPolicySnapshot(QosPolicyServiceImpl.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.referentia.commons.distributed.remoting.jms.JmsServiceExporter$1$1.run(JmsServiceExporter.java:189)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.sdf.configure.model.change.InvalidChangeException: can't add input service policy: policy has queueing
at com.sdf.configure.model.validate.RuleBasedValidator$RuleBasedChangeValidator.checkValidChange(RuleBasedValidator.java:5188)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:304)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:140)
at com.sdf.configure.model.validate.RuleBasedValidator.checkValidChange(RuleBasedValidator.java:1039)
at com.sdf.configure.model.change.SimpleConfigChanger.performChange(SimpleConfigChanger.java:126)
... 12 more
我想提取文本: 不能添加輸入服務政策:政策已經排隊
com.sdf.configure.model.change.InvalidChangeException: transformed change validation failed
at com.sdf.configure.model.change.SimpleConfigChanger.performChange(SimpleConfigChanger.java:129)
at com.sdf.portal.service.QosPolicyServiceImpl.applyPolicySnapshot(QosPolicyServiceImpl.java:99)
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sdf.commons.distributed.remoting.jms.JmsServiceExporter$1$1.run(JmsServiceExporter.java:189)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.sdf.configure.model.change.InvalidChangeException: compound change component validation failed
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:1309)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:361)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:140)
at com.sdf.configure.model.validate.RuleBasedValidator.checkValidChange(RuleBasedValidator.java:1039)
at com.sdf.configure.model.change.SimpleConfigChanger.performChange(SimpleConfigChanger.java:126)
... 11 more
Caused by: com.sdf.configure.model.change.InvalidChangeException: can't add input service policy: policy has shaping
at com.sdf.configure.model.validate.RuleBasedValidator$RuleBasedChangeValidator.checkValidChange(RuleBasedValidator.java:5180)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:304)
at com.sdf.configure.model.validate.AbstractContextChangeValidator.checkValidChange(AbstractContextChangeValidator.java:1306)
... 15 more
我想提取文本:
複合變更組件驗證失敗
不能添加輸入服務政策:政策已經成型
任何優雅的方式來做到這一點?找我要提取部分的唯一方法似乎是我想提取的作品總是在之前
產生的原因:com.sdf.configure.model.change.InvalidChangeException:
WOW ......有一天,我需要學習如何使用正則表達式..這就像一個冠軍。 – systemoutprintln