I want to create a custom exception message in case exception is thrown by my mule service. In order to do that, i want to separately capture mule generated ErrorCode. Is there any property using which i can get that value? I tried using #[org.mule.config.ExceptionHelper.getErrorCode(Exception.class)]" but this returned -1 as a value instead of the actual exception code.
What method can i use to fetch ErrorCode?
You are supposed to pass the class of the current exception, ie:
#[org.mule.config.ExceptionHelper.getErrorCode(exception.class)]"
exception is the current exception while Exception is the java.lang.Exception class for which there is no error code associated.
Related
When i create an object, it commits it correctly, however, when i edit it, i obtain the following exception:
12:32:20.244 [http-nio-8082-exec-9] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is JaversException SNAPSHOT_SERIALIZATION_ERROR: error while serializing snapshot of 'com.tesicnor.tcheck.equipment.data.model.Equipment/92849', duplicated property 'Field ValueType:String equipmentStatus, declared in Detectable'] with root cause
org.javers.common.exception.JaversException: SNAPSHOT_SERIALIZATION_ERROR: error while serializing snapshot of 'com.tesicnor.tcheck.equipment.data.model.Equipment/92849', duplicated property 'Field ValueType:String equipmentStatus, declared in Detectable'
My entity Equipment contains an equipmentStatus, and this entity extends from another one, named Detectable, which also contains a equipmentStatus field. However there are more fields where the same occurs. Any idea of how solving this error?
When you put two fields with the same name into one class - you are asking for trouble. It's the antipattern. Javers serializes object snapshots as a Map: propertyName -> propertyValue. Obviously, if you have duplicted fields a Snapshot can't be serialized properly. Try to remove duplicated field.
I have to create a a new exception (MultipleErrorException) which extends MySuperException class. I have another exception (SingleErrorException) which also extends MySuperException.
Looking at the pseudo code below:
for (a number of times)
try
call myMethod(myObject) that throws SingleErrorException
catch(SingleErrorException e)
add the caught SingleErrorException object to a
MultipleErrorException object where a mapping should
be created mapping myObject to SingleErrorException
I need to throw a single "MultipleErrorException" which holds a map (myObject-->SingleErrorExceptions).
Is there any other way to this rather than creating an initial MultipleErrorException object before the for loop, an then adding the mappings as the exceptions are caught?
Thanks
java.lang.Exception as such does not have any method to support your requirement.
If you need it, then one way is to add the Map variable in MultipleErrorException and setting the value of it, but again, editing the exception object is not good.
Instead, you can add the error messages to Map and return the map instead of throwing the exception from the method.
In Script#, is it possible to define your own exception classes? I cannot derive from Exception since it's sealed:
public class MyException : Exception {} // Cannot inherit from sealed class Exception
And if I try to throw an exception that doesn't inherit from Exception I get another error:
Error 22 The type caught or thrown must be derived from System.Exception
Seems like there is no support for this?
Its not possible.
You can't catch specific types in generated script. If you've got additional data you'd like to put on the exception, then the Exception type has members to hold on to additional data.
I'm using IAudioVideoCaptureDeviceNative and StartRecordingToSinkAsync. I need to get the bitrate lower and have been trying to set the H264QuantizationParameter property, but using it throws an exception. I am able to set an value before calling StartRecordingToSinkAsync and successfully get it using GetProperty, but when I call StartRecordingToSinkAsync CaptureServiceClient.dll throws an unhandled exception.
The documentation is basically non-existent on how to use this parameter or affect the bitrate, any ideas?
I have c#.net code which calls a method from another external/referenced .net assembly. This method I am calling throws an exception if a certain property from the object I am passing it is null. Here it is in a nutshell:
public void Add(string key, object obj)
{
..
//if the Foo property from obj is null then
throw new Exception("Foo property is null or empty")
..
}
In my client code which calls the DLL's Add method, I would like to be able to detect that this particular exception was raised, maybe distinguished by its "Foo property is null or empty" message. Currently, I get a NullReferenceException when it hits this method, so I catch this exception.
Question1:
Can I get the error message associated with the exception being thrown by the code I am calling (in the referenced assembly)??
Question2:
Is this considered bad practice or maybe just atypical?
Obviously, I can disassemble the third-party DLL to discover that my obj I'm passing in must have this "Foo" property set. So, my question here is somewhat for the sake of exercise (and because I'm a n00b).
Catching System.Exception and showing the exceptions Message property is all I needed. At first, I kept getting a NullReferenceException with "Object reference not set to instant of an object" message at the Add method, but I was expecting to get an Exception with the message "Foo property is null or empty" error. Some condition changed in my code and I now get what I expect.