cz.mmsparams.api.utils.ExceptionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MmsParamsAPI Show documentation
Show all versions of MmsParamsAPI Show documentation
Common library for MmsParams system
The newest version!
package cz.mmsparams.api.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import cz.mmsparams.api.exceptions.MmsParamsExceptionBase;
import cz.mmsparams.api.exceptions.SystemException;
import cz.mmsparams.api.websocket.messages.errors.GenericErrorResponseMessage;
public class ExceptionHelper
{
private ExceptionHelper()
{
}
public static String getStackTrace(Throwable exception)
{
if (exception == null)
return "";
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
return sw.toString(); // stack trace as a string
}
public static Exception generateException(GenericErrorResponseMessage error)
{
if (error == null)
return new Exception("GenericErrorResponseMessage not present");
return new Exception(error.toString(), error.getTestErrorModel().getException());
}
public static T castException(Throwable ex)
{
if (InheritanceUtil.isSubclass(ex, MmsParamsExceptionBase.class))
{
return (T) ex;
}
else
{
return (T) new SystemException(ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy